Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Detecting overlap of two kinematic mesh colliders

Discussion in 'Physics' started by SimonW, Apr 22, 2015.

  1. SimonW

    SimonW

    Joined:
    Feb 20, 2012
    Posts:
    13
    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:
    1. Drag them around with the mouse, detecting every collision/overlap, but not actually responding (ghosting through each other, but remembering what they move through).
    2. 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 o_O

    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.
     
  2. andrew-lukasik

    andrew-lukasik

    Joined:
    Jan 31, 2013
    Posts:
    239
    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.
     
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,430
  4. stanzy

    stanzy

    Joined:
    Dec 12, 2016
    Posts:
    17
    Edy likes this.