# Maximum Rotation[SOLVED - Thank you!]

Hi guys!

I want an object to rotate around an axis between 0 and 75 degrees.
How can i do that in JS?
I suppose i will have to add something like max rotation and min rotation…but how?

Here is my code:

``````if (Input.GetAxis("forfecare_Scroll")>0)
{
transform.eulerAngles.z  += VitezaRotatieRola *  Time.deltaTime;

}
``````

Thanks!

One way to do this is to define two rotations as Quaternions for the start and the end angle. You can then use Quaternion.Slerp to interpolate between them:-

``````var startRot = Quaternion.AngleAxis(0, Vector3.forward);
var endRot = Quaternion.AngleAxis(75, Vector3.forward);
var pos: float = 0;
var turnSpeed: float = 0.1;  // ...or whatever.

if (Input.GetAxis("forfecare_Scroll")>0) {
pos = Math.Clamp01(pos + turnSpeed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(startRot, endRot, pos);
}
``````

You should be able to use clamp shouldn’t you?
(If I recall right, clamp limits a max and min value.) Then just set the angle like you would normally.

Edit Note: I didn’t read the reply, so XD Sorry for the repeat kind of post.

Thank you andeeee

It works, perfectly, exactly waht i need. I modified a bit some parameters, but it’s good.

Thanks again, and keep on the good work!

Best forum ever - Unity3D forum