zoltana
zoltana

Reputation: 71

Unity 4.5 Mesh Collider Not Interacting with Circle or Box Collider 2D

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:

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.

Upvotes: 1

Views: 1369

Answers (1)

axwcode
axwcode

Reputation: 7824

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.

Upvotes: 1

Related Questions