Search Unity

OnCollisionStay events stop when non-kinematic rigidbody rests on kinematic rigidbody

Discussion in 'Editor & General Support' started by grojguy, May 16, 2013.

  1. grojguy

    grojguy

    Joined:
    Jul 13, 2009
    Posts:
    35
    [HR][/HR]
    EDIT: - I figured out my mistake... rhe rigidbody is going to sleep - which is a normal behavior. How embarrassing! :oops: But I'll leave my original post in case anyone else makes the same oversight.
    [HR][/HR]
    I have a very simple test case:

    - "the ball", a sphere with primitive sphere collider, and rigidbody, isKinematic = false
    - "the surface", a cube with primitive box collider, isKinematic = true
    - a script attached to either object, which prints OnCollisionEnter/Stay/Exit collision data to the editor console

    The ball is initially located above the surface (which is kinematic, i.e. fixed, not moving). When hitting 'play', the ball drops, contacts the surface, and the following events are output to the console:

    1. OnCollisionEnter
    - 1 event
    - velocity = 0,y,0 where y is an expected value based on height of ball and gravity setting)

    2. OnCollisionStay
    - n events, where n is in the range of 20-30, but varies according to initial height of ball
    - velocity = 0,0,0 for all n events

    The ball is now at rest on the surface, but no more OnCollisionStay events are occuring??

    According to the documentation I can find, this is unexpected behavior:

    Collider.OnCollisionStay

    In my test case, I have satisfied the conditions as highlighted above, yes?

    This definitely appears related to rigidbody.isKinematic = true setting of the surface. As a sanity check, if I edit the surface (cube with primitive box collider) and change the rigidbody to non-kinematic (and fully constrain its position rotation), I get the following (mostly expected) events:

    1. OnCollisionEnter
    - 1 event
    - velocity = 0,y,0 where y is same value as previous test)

    2. OnCollisionStay
    - n events, where n continues to increment for each frame, just as documentation says
    - velocity = 0,y,0 where y gradually decreases over approx 15 events, then settles at 1.1 for all continuing events? Shouldn't this y velocity be zero?? The ball is at rest on the surface, right?!!


    The script output is identical when attached to either object, with the exception of the sign of the velocity values (since it's a relative value).

    Am I crazy, or is this a bug? Or both? Is it possible I have somehow flubbed such a simple test case?

    Glaring head-scratchers:
    a. OnCollisionStay events between continuously-colliding non-kinematic and kinematic rigidbodies occur for some frames then stop?
    b. Relative velocity of "at rest" colliding rigidbodies is non-zero?
     
    Last edited: May 21, 2013