I’m needing to add the ability to look up/down in my game, which I have figured out, but I need to assign limits on how far you can look up and down.
How would I go about doing this with the simplest code possible?
I was thinking that a simple if-then statement saying that if the rotation is above 90 degrees upwards, it would go back to 89 would be ideal, but to do that I need to know how to get the angle of an object.
So what do?
Assuming that up/down is a rotation around your local x axis
// get your local rotation as euler angles
Vector3 localTempRot = transform.localEulerAngles;
// transform the range from 0 -> 360 to -180 -> +180
// not necessary, but it makes things easier
if(localTempRot.x > 180)
localTempRot.x = 360 - localTempRot.x;
// check and change if necessary
if(localTempRot.x > 90)
localTempRot.x = 89;
else if(localTempRot.x < -90)
localTempRot.x = -89;
//assign back to your object
transform.localEulerAngles = localTempRot;