1
\$\begingroup\$

In Unity3D (Version 5.3.1f1 Personal) I have a scene with a sprite with a Rigidbody2D and some sprites with a BoxCollider2D. The BoxColliders don't have the Is Trigger enabled and the RigidBody is not Kinematic, but they are not colliding. What am I doing wrong?

\$\endgroup\$
  • 2
    \$\begingroup\$ The RigidBody gameobject also requires a Collider in order for collisions to work \$\endgroup\$ – jgallant Aug 9 '16 at 17:02
1
\$\begingroup\$

Rigidbody2D is a component that gives the GameObject physics properties like gravity, mass, drag etc in a 2D environment.

BoxCollider2D is component that gives the GameObject a box shaped collision detector with certain surface properties in a 2D environment.

When you simulate physics in your game like object falling with gravitational acceleration, stop moving when in contact with another collision detector, having force applied etc you need both BoxCollider2D and Rigidbody2D.

In some case like non moving obstacles where we usually don't want physics simulation but just collision detection or trigger detection, Rigidbody2D can be ignored. But one of the collides must have Rigidbody2D in it for collision or trigger detection.

There is also layer based collision detection if you want work with layers of collision detection or ignorance.

\$\endgroup\$
  • \$\begingroup\$ The collision now works, but the player tilts when it touches a wall (see this GIF: i.imgur.com/llVGNPy.gif) \$\endgroup\$ – Jonas Kohl Aug 9 '16 at 18:53
  • \$\begingroup\$ try freezing Z rotation on the Rigidbody \$\endgroup\$ – spectacularbob Aug 9 '16 at 19:05
  • \$\begingroup\$ mark as right answer if things work for you. \$\endgroup\$ – Sourav Paul Aug 9 '16 at 19:35

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.