Search Unity

Sometimes Collision.impulse returns 0 during a hard collision, what could cause this?

Discussion in 'Physics' started by DivideByNil, Mar 31, 2016.

  1. DivideByNil

    DivideByNil

    Joined:
    Dec 4, 2015
    Posts:
    15
    I'm really stuck here.

    I have a sphere that will sometimes collide with a mesh collider wall. When that happens, I need to determine if I should play a bounce sound (i.e. did the sphere hit the wall hard enough to bounce). To do this, I check the collision impulse during OnCollisionEnter().

    Normally everything works fine. However, when the speed of the sphere is high enough, the impulse will return 0 on all three axises. Meanwhile, the game itself behaves normally, and the sphere bounces as expected -- clearly more than zero impulse is at work here.... but that's not what's being reported by Unity. This makes it impossible for me to determine if I should play a bounce sound.

    What would be causing impulse of a collision to be 0 on a hard collision?

    I'm using Unity 5.3.4

    UPDATE: I wrote some pretty ugly code to get around the issue. It turns out that whenever the absolute velocity of my sphere exceeded about 17.2 in any direction, collisions above that speed would return with a 0 impulse. Soooo I made a small array to hold the current and previous frame and during a collision I check the previous frame for sphere velocity and performed collision operations with that.

    Not sure if it's a Unity bug, a PhysX bug, or a DivideByNil quirk :p
     
    Last edited: Mar 31, 2016
  2. akareactor

    akareactor

    Joined:
    Apr 6, 2015
    Posts:
    108
    I faced a similar problem.

    Impulse turns to zero on x86 build, whilst impulse on a x86_64 build is ok.

    My experiments show a dependance between size of colliders, speed of a bullet and zeroed impulse on x86 build.
     
  3. Necronomicron

    Necronomicron

    Joined:
    Mar 4, 2015
    Posts:
    108
    I have similar thing with 2D physics in 2018.2.1f1. Sometimes normalImpulse just returns 0, randomly.
     
  4. Thaoren

    Thaoren

    Joined:
    May 15, 2015
    Posts:
    7
    This seems to still be an issue in 2018.3.5f1. The
    OnCollisionEnter( Collision collision )
    is being called correctly but
    collision.impulse
    is sometimes zero (including
    collision.impulse.magnitude
    , a flat zero.) Checking the number of collision contacts this happens with any number of contacts it would seem, including 1 - 6.
     
    Last edited: Feb 17, 2019
  5. Develax

    Develax

    Joined:
    Nov 14, 2017
    Posts:
    67
    The same bug in Unity 2019.1.6f1.
     
  6. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    153
    I'm using 2019.3.f4 and I encountered the same issue!
    So it has never been fixed since 2016 :eek:
     
    Last edited: Feb 4, 2020
  7. QNCY

    QNCY

    Joined:
    Nov 29, 2019
    Posts:
    2
    oleg_v likes this.
  8. levi9000

    levi9000

    Joined:
    Jan 25, 2014
    Posts:
    11
    Also encountering this issue in 2019.3.15f1. The impulse is usually zero, but sometimes not during OnCollisionEnter. Changing the physics settings and collision modes haven't helped. I did discover that OnCollisionStay seems to always have a valid value for the impulse, which is working for my needs even though I was afraid it would miss some collisions- if it is, it isn't noticeable.
     
  9. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    Running into this problem in 2019.4.10f1, x86_64 build, using discrete collisions. Played with all the various physics settings available, didn't find a solution. All the other data in the Collision seem to be in order, but impulse for some reason is just zero. This is pretty critical to our game, so I'll defs keep investigating.

    EDIT: A solution that worked for our situation was to increase the Default Contact Offset in the physics settings from 0.01 to 0.1. This ensured that smaller collisions correctly passed their impulse values.
     
    Last edited: Nov 11, 2020