Rotating between 2 extreme angles in Unity C#
Ok, so this is likely a really basic solve, but I can't for the life of me puzzle it out. I'm trying to rotate an object in 2D up to positive or negative 10 degrees, depending on the direction of movement (right or left). At this stage my code looks like this :
This just rotates the object eternally in one direction or the other - it does change direction, but it needs to stop. Oh won't you please, please help me (help me, help ooooooooooh).
void Update () { if(MoveMods.driftRight && transform.rotation.z >= 350) { transform.Rotate(0,0,-1); }else if (!MoveMods.driftRight && transform.rotation.z <= 10) { transform.Rotate(0,0,1); } }
This just rotates the object eternally in one direction or the other - it does change direction, but it needs to stop. Oh won't you please, please help me (help me, help ooooooooooh).
Comments
The object now gets stuck after rotating to one of the limits, because (I think) that within the update, it exceeds the limit by some tiny value, and therefore lies out of range. I can't see any way around this at this stage.