2D character rotation wrong direction when moving

Hi there,
I have seem many questions like this but none seem to help me fix my issue! So when my player moves in a direction, the cone of light that is on him is facing the opposite direction and i cant seem to figure out why? Here is my code:

   if (playerJoyStick.inputDirection != Vector2.zero)
        {
            float angle = Mathf.Atan2(playerJoyStick.inputDirection.y, playerJoyStick.inputDirection.x) * Mathf.Rad2Deg;
            localPlayerInstance.transform.localRotation = Quaternion.AngleAxis(angle, Vector3.forward);
            movement = playerJoyStick.inputDirection;
        }

In the picture you can see that the joystick is facing up however the cone of light is facing down…
Thanks for any help in advance!

Hey airbagnr1,


Perhaps localPlayerInstance.transform.localRotation = Quaternion.AngleAxis(angle + 180f, Vector3.forward); could do the job?

Else try localPlayerInstance.transform.localRotation = Quaternion.AngleAxis(angle, Vector3.back);


If not, take a proper look at how they influence your situation and perhaps that leads you to the solution. Maybe combining both even works, it’s a matter of trying out different things with these values.


EDIT: Is there a certain reason why you’re not just using Vector2.Angle?


-BelgianWizard, peace