This is what happens when my player character jumps and collides with a platform from the side. The player character tilts over or ends up upside-down or sometimes on its back.

How can I prevent this?

Screenshot of Unity editor showing a rectangular character hitting a platform with its feet, and tilting over

  • \$\begingroup\$ What's your desired outcome here? Is it to keep the player vertically oriented at all times, without being able to be knocked over? \$\endgroup\$ – doppelgreener Apr 26 '19 at 9:59
  • \$\begingroup\$ yes, doppelgreener \$\endgroup\$ – Mr.gon96 Apr 26 '19 at 12:32
  • \$\begingroup\$ looks like you need to freeze the rotations of the rigid body. you can adjust this in code behind or in the inspector at the rigidbody component. Also a helpful note is to parent the player transform to the platform when in contact with it. Especially if both objects can move simultaneously. \$\endgroup\$ – Justin Markwell Apr 26 '19 at 15:03

Inside your character's Rigidbody2D component, expand the "Constraints" fold-out, and tick the "Freeze Rotation Z" box. This will ensure that physics impacts can't cause your character to spin.

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.