Constraining rotation in 2D

I’ve been making a plants vs zombie clone with some tutorials but I found my zombies when they got backed up against each other started rotating and going off at funny angles.

I fixed the problem by using a slider joint 2d and constraining the angle but while trying to figure it out I came across…
Rigidbody2D.freezeRotation
Rigidbody2D.constraints
RigidbodyConstraints2D

I was wondering if using one of these is a more efficient way of doing it, what’s the difference and how do they work as the API doesn’t have any examples?

I’m guessing it’s something like… this.GetComponent<Rigidbody2D>().
but I’m still learning so I’m not quite sure.

Thanks for any help!

In the newest version of Unity (5.1.1) there is an option in the inspector for the Rigidbody2D component to ‘freeze’ rotation (Z). Enable that and see if it solves your issue.

If you’re on an earlier versions of Unity, it was available as well just had a different name, just can’t remember what it was…

1 Like