- Home /
Question by
jdquirino07 · May 26, 2021 at 12:31 PM ·
c#rotationflipping
How to test if rotation is within a range?
I'm working on my first game jam with little to no C# knowledge and I'm trying to make my sprite flip when the gun is rotated above -90 degrees and below 90 degrees I don't know why it doesn't flip anywhere from 0 to -90
if(gun.transform.eulerAngles.z >= -90 && gun.transform.eulerAngles.z <= 90) {
transform.rotation = Quaternion.Euler(0, 0, 0);
} else {
transform.rotation = Quaternion.Euler(0, 180, 0);
}
Comment
Assu$$anonymous$$g this is 2D project and transform.right
is your pawn "forward" direction and gun.transform.right
is the gun "forward" direction:
if( Vector2.Dot( transform.right , gun.transform.right ) < 0.0f )
{
transform.rotation *= Quaternion.Euler(0,180,0);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613034211im_/https://answers.unity.com/themes/thub/images/avi.jpg)