Lock axis rotation on RigidBody
I'm trying to prevent an object from rotating on any axis except the x axis.
I'm trying the following:
Rigidbody rb = gameObject.GetComponent<Rigidbody>();
rb.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
When doing this over time the gameObject still rotates a little which is causing me problems.
I therefore tried to add
Quaternion.Euler(transform.rotation.eulerAngles.x, 0, 0);
This fixes it rotating on the y and z axis, but with the way Quantenion's store information (from the little I understand) I shouldn't really be doing this and once it hits 90 degrees of rotation it just jumps around.
What way should I be doing this? I don't want to change what the physics engine is already doing to the x axis, but just want the Y and Z to be fixed and not rotate.
I'm having this same problem...
Have you had any luck, yet?
Your answer
Follow this Question
Related Questions
Having two objects Y axis parallel rotating around local Z axis. 0 Answers
How to add to a rotation angle? 0 Answers
Gimbal Lock Problem 1 Answer
Trying to dynamically animate a Gimbal? 0 Answers
How to rotate a local axis of an object to another object? 0 Answers