Search Unity

Unity Physics Collision Execution Order Error?

Discussion in 'Physics' started by ROMgame, Sep 19, 2015.

  1. ROMgame

    ROMgame

    Joined:
    Sep 8, 2013
    Posts:
    4
    So in my game I have two wall objects, "Left Wall" and "Right Wall". They are separated by a large empty room.

    I then have an object attached to the right wall, when I tap the mouse button the idea is that a large force will be applied to the object on the right wall to fling it onto the left wall in a single frame. The problem is - the following happens:

    1. The mouse button is pressed and the object that is attached to the right wall has its velocity modified during the next frames "FixedUpdate()" - increasing it to a very, very high value.

    2. Following the "FixedUpdate()", "OnCollisionEnter()" is automatically called - telling the object that it has entered the left wall - as expected.

    3. "Update()" is automatically called on all objects.

    4. "OnCollisionExit()" is automatically called - telling the object that it has exited the right wall
    So that's pretty weird - the object should be told it has exited the right wall at the same time it's told that it has entered the left wall (before Update) - right? They definitely are not overlapping - i've separated them by huge amounts of space to be sure. So why isn't OnCollisionExit being called right after FixedUpdate? Very puzzling!

    Note : My actual use case is not the above - the above is just a simplified version I've been testing to help me to debug why OnCollisionExit isn't getting called straight after FixedUpdate!

    Any help would be much appreciated - I'm at a bit of a loss for how to solve this one!