# Limit rotation angle on Z axis while slerp

hii,…

I am doing slep of rotation and i want to set maximum rotation angle to -3 and minimum rotation angle to 17.

But i dont understand how do i set. code i have used for slep is here :

``````	// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown (0)) {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, 100)) {
if (hit.collider.name == "LeftCollider") {
finalRotation = Quaternion.Euler (0, 0, 5) * kite.transform.rotation;
if (kite.transform.eulerAngles.z < 14 || kite.transform.eulerAngles.z > 350) {
rotating = true;
StartCoroutine (rotateKiteDown ());
}

}
if (hit.collider.name == "RightCollider") {
finalRotation = Quaternion.Euler (0, 0, -5) * kite.transform.rotation;
if (kite.transform.eulerAngles.z < 16 || kite.transform.eulerAngles.z > 350) {
rotating = true;
StartCoroutine (rotateKiteUp ());
}
}
}
}

}

IEnumerator rotateKiteUp ()
{
while (kite.transform.rotation != finalRotation) {
kite.transform.rotation = Quaternion.Slerp (kite.transform.rotation, finalRotation, Time.deltaTime * 2.5f);
yield return 0;
}
kite.transform.rotation = finalRotation;
}

IEnumerator rotateKiteDown ()
{
while (kite.transform.rotation != finalRotation) {
kite.transform.rotation = Quaternion.Slerp (kite.transform.rotation, finalRotation, Time.deltaTime * 2.5f);
yield return 0;
}
kite.transform.rotation = finalRotation;

}
``````

Ekta. Conceivably, just use `void LateUpdate()` and very simply look in there at the eulerAngles, and crush them down to your limits.

(So, quite simply like …

``````e = ... eulerAngles
newZ = Mathf.Clamp( e.z, -3f, 17f)
e.z = new Z
.. eulerAngles = e
``````

… and you’re done.)

It’s quite difficult to fight against slerping, you could get flicker.

IT can be very, very difficult to achieve what you’re up to, but using the “trick” of LateUpdate can work in certain ranges of motion. Hope it helps.