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

Continuous Collision Detection Incompatible with Kinematic Bodies?

Discussion in 'Editor & General Support' started by sybixsus2, Feb 24, 2011.

  1. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    Am I correct in thinking that continuous and continuous dynamic collision detection is not compatible with kinematic rigid bodies? I find that enabling CCD and CC for the dynamic and static collision meshes does not have any effect. The collisions go straight through, just as they do with discrete collisions. Just wanted to make sure that this is "by design" rather than "by chance".
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The Continuous Dynamic collision setting only has an effect on non-kinematic rigidbodies. It is relevant for moving objects but not for stationary objects that they may come into contact with.
     
  3. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    Yeah, I thought it was probably intentional, but it's a shame. If I let the physics engine take control of the bodies, slow moving objects gently embed themselves into objects. If I disable the physics engine and write my own physics, the collision engine can't keep up and fast moving objects go straight through objects. So it seems that - if I want to have fast moving objects at all, I need to write my own collision functions as well.
     
  4. Baalhug

    Baalhug

    Joined:
    Aug 12, 2013
    Posts:
    32
    For anyone reading this who needs to enable "is kinematic" temporarily in an object with CCD, you can:
    Code (CSharp):
    1. rigBody.collisionDetectionMode = CollisionDetectionMode.Discrete; // you can use Speculative too
    2. rigBody.isKinematic = true;
    3. rigBody.detectCollisions = false;
    4. // move your object as you want
    5. rigBody.detectCollisions = true;
    6. rigBody.isKinematic = false;
    7. rigBody.collisionDetectionMode = CollisionDetectionMode.Continuous;
    And it will work.
    If you only enable and disable isKinematic on rigidbody with CCD, Unity will change its CollisionDetectionMode to Speculative. If this happens you can Debug.Log(rigBody.CollisioniDetectionMode) and it will tell you it is Continuous, but it's not true, it is Speculative, as you can check with ghost collisions and other behaviours.
    This was tested with Unity 2018.3.6f1

    Cheers
     
    Yiming075 and Kyodan like this.