1
votes

I am new to unity and I am working on a 2D game. Currently, I am having trouble getting two colliders to interact when one of them is a mesh collider and the other is a box or circle collider. I was originally working to get the Unity Sample Assets 2D character to interact with a mesh terrain. When I "played" the game, the circle collider attached to the legs of the character was falling through the mesh terrain. I have simplified the problem and created two cubes:

  • One cube I upload and keep the 2d box collider and add a rigid body to
  • The second cube I delete the 2d box collider and add a mesh collider

I place the second cube under the first cube and hit "play". The top cube falls through the bottom box. When I replace the bottom cube's mesh collider with a box collider and hit "play" it correctly collides and stops on the box. I'm guessing I'm making the same mistake in this simplified example as I am in the more complicated 2D Character scenario. Do you have any suggestions of what I am doing wrong? I have tried making the mesh collider convex (although I believe this should only be necessary between two mesh colliders?). I have also ensured that the z position is the same as well as the layers of the two objects.

1
I think I have found the issue. I think the problem is that the mesh is a 3D collider which cannot interact with 2D colliders. When I change it to 3d box colliders it interacts properly with the mesh collider. Is this correct?zoltana

1 Answers

1
votes

You cannot collide a 3D object against a 2D.

void OnCollisionEnter2D(Collision2D coll) 
{
    // Code here is clueless about 3D.
}

API Reference.

Sent when an incoming collider makes contact with this object's collider (2D physics only).

You could cheat a little. Before Unity had 2D colliders what people would do is create a very thin box collider3D, which in your case should work.