1

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.

4

1 に答える 1

1

3D オブジェクトを 2D に対して衝突させることはできません。

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

API リファレンス

着信コライダーがこのオブジェクトのコライダーと接触したときに送信されます (2D 物理のみ)。

少しごまかすことができます。Unity が 2D コライダーを使用する前は、非常に薄いボックス collider3D を作成することでした。これは、あなたのケースでは機能するはずです。

于 2014-10-26T05:37:42.590 に答える