Question by 
               Unconscious · Nov 13, 2016 at 10:28 PM · 
                rotationclampclamped rotation  
              
 
              Is this a good way to Clamp a Rotation?
The code below works fine but somehow when I try to rotate the object again when it reaches the minClamp and the maxClamp it seems somehow delay when I pressed a key to rotate it.
     public float minClamp = 0.0f; 
     public float maxClamp = 90f;
 public float speed = 5.0f;
 private float zRotation = 0.0f;
 void Update () 
 {
     zRotation -= Input.GetAxis ("Horizontal") * speed;
     transform.eulerAngles = new Vector3(0.0f, 0.0f, Mathf.Clamp(zRotation, minClamp,     maxClamp));
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by flashframe · Nov 13, 2016 at 10:30 PM
You want to clamp the zRotation value first, otherwise it'll keep accumulating while you hold the axis:
 void Update () 
  {
      zRotation = Mathf.Clamp(zRotation - Input.GetAxis ("Horizontal") * speed, minClamp, maxClamp);
      transform.eulerAngles = new Vector3(0.0f, 0.0f, zRotation);
  }
 
              Answer by Lairex59 · May 02, 2020 at 12:36 PM
Just by the way here it's explained well https://www.youtube.com/watch?v=JeF0hoJWLz4
Your answer
 
             Follow this Question
Related Questions
Object don't rotate correctly 1 Answer
MathF clamp look toward mouse pointer not working correctly 0 Answers
How to Clamp a 3rd Person Camera's x-axis Rotation? 0 Answers
Clamp a 2D object controlled by the mouse 0 Answers
Euler angles clamping issue 0 Answers