# Setting joint angle from a slider makes joint spin continuously [closed]

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;


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?

• 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. 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);


or

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


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