- Home /
Is my if statement changing my Euler angle value?
I'm trying to clamp rotation and I've found the strangest thing. My debug is showing me a value that represents change in Euler angle. Problem is, this is either shown as a change from zero, or a change from 360, depending on... the code in my if statement, by all appearances.
Anyone know what's causing this?
This prints values as change from zero, such as 0.247:
float pitch = transform.eulerAngles.x + mouseY;
if ((pitch < (360 + LookDownClamp)) && (pitch > (360 -LookUpClamp)))
transform.Rotate(-mouseY, 0, 0);
Debug.Log(pitch);
Whereas this prints values from 360, such as 360.247:
float pitch = transform.eulerAngles.x + mouseY;
if ((pitch < LookDownClamp) && (pitch > -LookUpClamp))
transform.Rotate(-mouseY, 0, 0);
Debug.Log(pitch);
I'm failing to understand this, and I don't think it's just the stout at my side (could be, though). Anyone have an explanation to share?
Answer by sacredgeometry · Dec 05, 2021 at 09:58 PM
No it isn't.
To prove it put this line before the other log statement
Debug.Log($"{transform.eulerAngles.x} + {mouseY}");
To further prove it. pitch is a float. Floats are structs. Structs are passed by value not reference. There is nothing you could have done short of an assignment that would have changed it.
In the greater context what you are changing is the transform so if you were to call it again then the two would behave differently