- Home /
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!
Answer by gsegers · Mar 08, 2018 at 04:45 PM
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
Hi gsegers, aye thanks a lot! Your answer gave me a few ideas and managed to fix it! Thanks a lot! However, I do have one question, with Vector2.Angle, is that not just between two game objects the angle is returned? Not sure how using that would have solved this issue? Am i understanding it wrong?
Your answer
Follow this Question
Related Questions
Trying to rotate a 2D image over time to a specific angle, but it's rotating its Y value every time 1 Answer
Help with rotating a sprite with mouse. 2 Answers
[2D] Rotations become tighter the further left they are? 1 Answer
What causes this object to re-rotate itself after it hits it's destination? 1 Answer