Search Unity

Inconsistent collision detection on slow-moving objects

Discussion in 'Physics' started by Michael_Waltham, Mar 12, 2017.

  1. Michael_Waltham

    Michael_Waltham

    Joined:
    Aug 20, 2014
    Posts:
    31
    So in a nutshell, we are using a gun to shoot spheres that stick to the floor. The spheres are moved using Unity's rigidbody code (i.e. I simply set the rigidbody's velocity when fired). When the sphere's collider intersects the floor's collider, the sphere is immediately halted by setting the usual data such as zero velocity and isKinematic = true. However, the collision is detected later than expected, and as a result the spheres intersect the floor at varying depths (see the image below). I would expect a problem like this to occur with fast objects, however these spheres are moving quite slowly, and I could swear I've never had a problem like this with slow moving objects before.

    I have tried setting their rigidbodies to continuous dynamic while firing them at another continuous object, to no avail. Reducing the physics timestep to around 0.005 (from 0.02) DOES alleviate the issue quite well, but doing 4x the usual physics steps feels a bit heavy given these are slow moving objects. Surely with the default physics step of 0.02 there shouldn't be as bad a problem as what I'm currently having.

    89682-collisions.jpg
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's important to specify what version of Unity. for example beta has a bug with delayed collision...

    In any case you should be able to get away with a timestep of 0.02 or even higher if you merely record the start direction and position per blob. Then whenever it collides, just fire a ray from the start position along that direction and position the blob with perfect accuracy.

    Perhaps the problem is that the object has low friction so it slides a bit before your code kicks in? Just thoughts.
     
  3. Michael_Waltham

    Michael_Waltham

    Joined:
    Aug 20, 2014
    Posts:
    31
    My Unity Version: 5.5.0f3.

    With regards to the blob objects, they only use trigger spheres and do not actually do physics collisions. OnTriggerEnter simple halts the objects. They do use gravity however so using your suggested raycasting method wouldn't work unfortunately :(
     
  4. Michael_Waltham

    Michael_Waltham

    Joined:
    Aug 20, 2014
    Posts:
    31
    Alright, so I did some more testing. I ran it frame-by-frame in order to check if it detects the collision on bullet impact. It seems to be detecting the collision a frame too late. In the attached image, I was simulating frame-by-frame, here it should have detected the collision however it only detects it in the following frame.

    Any suggestions on what is going wrong here?
     

    Attached Files:

  5. Michael_Waltham

    Michael_Waltham

    Joined:
    Aug 20, 2014
    Posts:
    31
    Bump ** Sorry guys really need suggestions on this :/
     
  6. LeRan

    LeRan

    Joined:
    Nov 24, 2015
    Posts:
    118
    I've been experimening a problem that I think has the same cause as yours, here is the best explanation I could find :
    https://forum.unity3d.com/threads/elastic-collision-and-angular-momentum.459253/#post-2992035

    Long story short, it seems that for arbitrarily slow moving objects, Unity decides that discrete collision detection is good enough no matter what you chose.

    The workaround I reluctantly adopted was to write my own collision fixes and apply them on OnCollisionEnter (in your case, set transform.position.y = ballDiameter/2 for example ?)
     
  7. Michael_Waltham

    Michael_Waltham

    Joined:
    Aug 20, 2014
    Posts:
    31
    Hmmmm. It seems that they never really found a solution to the problem. It seems to be that PhysX disables continuous collision detection below a certain velocity to improve performance.

    The only workaround I have seen is to change the fixed timestep (which impacts heavily on performance)