Restricting rotation for RigidBody

Hi,

I’m new to Unity, i’m building a 2D game. I would like to restrict rotation on the X and Y axis, and just allow rotation on the Z axis.

I was thinking of adding a rotation in the update function that would negate any rotation done by the physics engine. I don’t think that’s a good idea though…

Anyone have any thoughts?

Thanks,
Felix

Try this:

function FixedUpdate ()
{
     rigidbody.angularVelocity.x = 0.0;
     rigidbody.angularVelocity.y = 0.0;
}

function Update ()
{
     transform.eulerAngles.x = 0.0;
     transform.eulerAngles.y = 0.0;
}

i ran into quite a few problems by directly altering angularVelocity. your should rather use

component → physics → configurable

and set ‘Angular XMotion’ and ‘Angular YMotion’ to fixed

Thanks! That solved it.

Felix