- Home /
Maximum Rotation
Hey, here is a new one for you!
I want a maximum and minimum angle and I came up with this
function Update () {
if (transform.eulerAngles.y > 10)
transform.eulerAngles.y = 10;
if (transform.eulerAngles.y < -10)
transform.eulerAngles.y = -10;
}
But for some reason it's making my object rotate but kinda stutterly. This object is being moved by mouse with this script:
static var autoRotate : boolean; var rotateSpeed : float = 10; var MousePos : float; var XPos : float = 0;
function OnMouseDown () { autoRotate = true; }
function OnMouseUp () { autoRotate = false; }
function LateUpdate () {
MousePos = Input.GetAxis("Mouse X"); XPos = (-MousePos * rotateSpeed);
if (autoRotate)
transform.Rotate(Vector3.up * XPos);
}
Now I my question; where do I, or Unity, go wrong?
Retagged $$anonymous$$ax to $$anonymous$$aximum to prevent confusion with 3dsmax. Retagged $$anonymous$$in to $$anonymous$$inimum... for symetry :p and because there were 2 '$$anonymous$$inimum'-Tags but only this one '$$anonymous$$in'-Tag. Greetz, $$anonymous$$y.
Answer by AngryOldMan · Mar 12, 2011 at 05:25 PM
this bit
function Update () {
if (transform.eulerAngles.y > 10)
transform.eulerAngles.y = 10;
if (transform.eulerAngles.y < -10)
transform.eulerAngles.y = -10;
}
should be like this
function Update ()
{
if (transform.eulerAngles.y >= 10)
transform.eulerAngles.y = 10;
if (transform.eulerAngles.y <= -10)
transform.eulerAngles.y = -10;
}
and change your floats to ints. As far as I know int will work with decimal placing and floats will not. Maybe just the way that I'm using them but it's working for us so worth a try.
floats store decimals and ints don't. And Euler Angles are stored as floats.
like pete says u can get decimals in floats I think it's just how I've been using them.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Restrict min/max rotation STILL wont work 1 Answer
Mouse look X axis not working? 0 Answers
How to set maximum and minimum rotation for an object 2 Answers