Hello there,
I have this object that is holding another object and rotating it along the z Axis.

The thing is that as soon as the z-axis is above 90 degress or -90 degress I want to flip the Object ( gun ) on the oposite direction so doesn’t look weird.

I’m not sure how can I evaluate the angles here…
You might not need to evaluate the angles.
From the transform of the gun anchor (not the gun visual!) you can get things like transform.up
and transform.right
You can often structure things so that when the gun anchor is facing right, you show the gun visual normally, and when the gun anchor is facing left, you show the gun visual flipped.
Something along the lines of:
bool flipx = false;
// are we facing the muzzle anywhere left?
if (GunAnchorTransform.right.x < 0)
{
flipx = true;
}
GunSpriteRenderer.flipX = flipX;
1 Like
Thank you Kurt-Dekker
I have totally forgot about the Flip x & y value that have the Sprite Renderer component.
I also debug the transform.localEulerAngles.z and noticed that the angles were running in positive values all the time ( 360 ° )
if (transform.localEulerAngles.z > 90f && transform.localEulerAngles.z < 270f) gunSprite.flipY = true;
else gunSprite.flipY = false;
You have pointed me in the right direction. Cheers !
Unfortunately you can’t rely on Euler angles at all… Remember Mark Twain’s famous quote?
“Lies, damned lies, and statistics.”
Today it would be “Lies, damned lies, statistics and Euler angles from a Transform.”
There’s actually math behind it… here’s why:
https://starmanta.gitbooks.io/unitytipsredux/content/second-question.html
1 Like
Thanks again, this article is great and is giving me an understanding of a few things, example: when I put Debug Mode on Unity to see the values of the eulerangles from the transform component, I noticed that there were no 0-359° information and instead there was some 0 & 1’s with bunch of different behaviours.