- Home /
Question by
WatTheDeuce · Feb 23, 2021 at 01:33 AM ·
c#rotationrigidbodyclamp
How to clamp X axis rotation of a GameObject with a Rigidbody attached.
I have a GameObject with a Rigidbody and I want to limit it's X rotation to the range of (-35, 35). Here's what I tried:
public Rigidbody rb;
void FixedUpdate()
{
float rotX = rb.rotation.eulerAngles.x;
rb.rotation.eulerAngles.Set(Mathf.Clamp(rotX, -35f, 35f), rb.rotation.eulerAngles.y, rb.rotation.eulerAngles.z);
if(rb.rotation.eulerAngles.x > 35f)
{
Debug.LogWarning(rb.rotation.eulerAngles.x);
}
}
Any help is appreciated, thanks.
Comment
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Rotate player (rigidbody) towards his movement 2 Answers
C# Clamp joystick rotation 0 Answers
Camera global rotation clamping issue 0 Answers
How to rotate an object to a specific angle with angularVelocity? 0 Answers