- Home /
Weird Rotation Issue
I'm currently working out an aiming system in a 2d top-down game. I've currently got the player's weapon as the child of an empty game object that I can rotate to look at the mouse. I wanted to add another bit of code that made it so when the player is aiming to the left of their character, the gameobject's scale flips direction so the weapon is facing up on the left side. The code works perfectly fine whenever I am aiming to the top right (0 - 90 degrees), top left (90 - 180 degrees) and bottom left (-90 - -180 degrees), but it stays flipped on the bottom right (0 - -90 degrees) instead of returning to the normal direction. Here is the code that I'm using for this, and it's inside of an update.
if (transform.localEulerAngles.z > 90 || transform.localEulerAngles.z < -90)
{
transform.localScale = new Vector3(1,-1,1);
}
else if (transform.localEulerAngles.z < 90 || transform.localEulerAngles.z > -90)
{
transform.localScale = Vector3.one;
}
Comment