- Home /
 
Max rotation degrees
Hi guys I 've write the script attachment, where I would like to stop the rotation at 30 degree and when the key is not press the rotation return to original position 0.
// Update is called once per frame void Update () { if (Input.GetKey(KeyCode.RightArrow)) transform.Rotate(Vector3.back rotationspeed Time.deltaTime);
Thank you all
Answer by dishant27 · Mar 04, 2018 at 09:15 PM
 if (Input.GetKey(KeyCode.RightArrow)) 
 {         transform.Rotate(Vector3.back*rotationspeed*Time.deltaTime);
            transform.rotation = Quaternion.Euler(transform.rotation.x, 
                                                  transform.rotation.y , Mathf.Clamp(transform.rotation.z, minRotationValue, maxRotationValue));
 }
 else{
 transform.Rotate(Vector3.forward*rotationspeed *Time.deltaTime);     
            transform.rotation = Quaternion.Euler(transform.rotation.x, 
                                                  transform.rotation.y , Mathf.Clamp(transform.rotation.z, minRotationValue, maxRotationValue));
 }
 // in your case minRotationValue = -30 & maxRotationValue = 0
 
              Your answer
 
             Follow this Question
Related Questions
how to make a detect rotation script for negative rotation too 2 Answers
When applying a 90 degree rotation to Euler Angles, it is over/undershooting sometimes.. 2 Answers
How do I rotate an object when I press down a key and then it rotates back when I release the key 0 Answers
Translate speed keeps changing 1 Answer
Why one of object's animation has global rotation data, and another has local rotation data? 0 Answers