I am trying to flip my 2D character’s upper body based on which side of the character’s body the cursor is. Currently, If the cursor is on left side of the body, the character will flip to face left, and vice versa.
The problem is that if I rotate my character, It doesn’t adapt to the new rotation, instead it will flip based on the x coordinate alone.
How can I make it so that the body flips based on what side of the body the cursor is on regardless of its rotation? Like in the picture below, if the cursor was in the red the body would flip to face the left, if in the green, to the right.
Here’s my current code:
// flip bod and head according to mouse position
if (Input.mousePosition.x - Camera.main.WorldToScreenPoint(playerBod.position).x > 0 && !bodFacingRight) //if positive, turn right
FlipHeadAndBod();
else if (Input.mousePosition.x - Camera.main.WorldToScreenPoint(playerBod.position).x < 0 && bodFacingRight)
FlipHeadAndBod();