Detecting overlap of two kinematic mesh colliders

I’m having trouble figuring out the best configuration of triggers/colliders to fix a problem, and I was hoping someone could give me some suggestions.

The situation: I have a bunch of objects sitting around on a plane. They’re essentially extrusions of 2D polygons into 3D space, so they’re not guaranteed to be convex. I need to be able to:

  • Drag them around with the mouse, detecting every collision/overlap, but not actually responding (ghosting through each other, but remembering what they move through).
  • Resize them, pushing some objects out of the way to make room, and being blocked by others.

I had this working in Unity 4.6 using an incredibly overcomplicated system of colliders, triggers, sweep colliders and raycasts. It was horrible, but it worked. The objects had trigger and non-trigger mesh colliders, and the triggers handled overlap while the non-triggers handled collision. In Unity 5 concave mesh triggers are gone, so I need to find another solution. I’m currently trying to move the object around with Rigidbody.MovePosition, but I’m getting no collisions reported. Turning off IsKinematic while an object is moving sort of works for BoxColliders (ish), but “Non-convex MeshColliders with non-kinematic Rigidbodies are no longer supported in Unity 5.0”.

I haven’t even got on to the bit with actual collisions yet :eyes:

So, in summary: is there any way to move a non-convex mesh around and have it interact with another non-convex mesh? I could probably rewrite all this to use Physics2D, but I don’t want to go there if I can possibly avoid it.

You probably can write a simple method that goes through all triangles in both meshes (converted to world space of course) and tests if any of them intersects each other on this 2d plane. This would be your collision detection check on demand and without any use of complicated physics workarounds.

This might help…

Use the NonConvexMeshCollider script to solve your problem:
http://www.productivity-boost.com/DownloadNonConvexMeshCollider.html
I implemented that by myself because I had the same problem.

1 Like