- Home /
Question by
indeyetz · Jul 11, 2014 at 09:33 AM ·
rotationquaternionlimitz-axis
Trouble - Limit rotation on Z-axis
I'm trying to limit rotation of 2D character on Z-axis. That character is game object with rigidbody component and I applied AddForce to move it. I used code on below and got a strange result when my character constantly and weirdly change its rotation on Z-axis for a lot of times per second. What is wrong in this code?
Thanks in advance.
float horizRotate. ;
float curRotate;
void Start()
{
curRotate = transform.eulerAngles.z;
}
void LateUpdate()
{
horizRotate = curRotate;
horizRotate = Mathf.Clamp(horizRotate, -45, 45);
transform.rotation = Quaternion.Euler(0, 0, horizRotate);
}
Comment
Your answer
Follow this Question
Related Questions
Limit Rotation of Rigidbody to 45 Degrees (Handlebars on a Bicycle) 1 Answer
How to compare rotation position with an Int value (2D game) 1 Answer
[2D] Player's arm following the mouse 1 Answer
Euler angle problems with rotation limit script 3 Answers
Preventing rotation of rigidbody at a specific rotation 0 Answers