I use sliders to change the rotation angle of my joint, like this:

a = sliderx.GetComponent<Xslider>().sl.value;
b = slidery.GetComponent<Yslider>().sl.value;
headjoint.transform.Rotate(a, b, 0);

After I slide the bar, the joint continues rotating around and won't stop.

It's like it's doing

a += value

and not

a = value

Shouldn't the slider give me a single definite number?

Why? Do I need to use Euler angles?

  • \$\begingroup\$ I’m voting to close this question because it is a crosspost from StackOverflow. Crossposting on stack exchange sites is not allowed. Select the site where you think you'll get the best/most answers and ask only there. \$\endgroup\$
    – Vaillancourt
    Dec 17 '21 at 14:37

You are calling the wrong method for what you want to do.

As you can see explained in the documentation, Transform.Rotate applies an incremental rotation to an object, on top of whatever rotation it already had.

It explicitly promises to do a a += value

So if you want a = value then don't use this function, because it does not do that!

You want something like this instead:

headjoint.transform.localEulerAngles = new Vector3(a, b, 0);


headjoint.transform.localRotation = Quaternion.Euler(a, b, 0);

Notice that these both express a = value instead of a += value.


Not the answer you're looking for? Browse other questions tagged .