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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

2D collisions detected 2 frames later in Unity 5.3

Discussion in 'Physics' started by Pixelnest, Jan 12, 2016.

  1. Pixelnest

    Pixelnest

    Joined:
    Oct 25, 2013
    Posts:
    27
    Hello,

    I had to update our project from Unity 5.1 to Unity 5.3.0f4 (for console support mostly).

    It went globally well, but the physics seems to be a bit different in 5.3.0f4 and it's breaking the game.

    The game is a shoot them up. When a projectile hits an enemy, it gets destroyed.

    So far, nothing fancy: bullets and enemies have a Collider2D, a Rigidbody2D, and everything was working perfectly and precisely in 5.1.
    Bullets are moving using the rigidbody2d.velocity in a FixedUpdate, but the same issue also happens with the rigidbody2d.MovePosition function.

    The issue is that in 5.3.0f4 we now have a 2 frames delay between the collision and the OnCollisionEnter2D / OnTriggerEnter2D events.

    The result is fast bullets going through enemies:



    The bullets still get destroyed (events are raised) but we can't allow this 2 frames delay.

    I tried a lot of things, all failed:
    - Tweaking the Physics2D manager values
    - Setting all rigidbodies to "Never sleep"
    - Trying Kinematic / non-kinematic & continous collision rigidbodies

    Any idea?
    One again, this is working perfectly fine with an accurate and "instantaneous" collision in 5.1...

    Thanks.
     
    Last edited: Jan 12, 2016
  2. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    Hi,

    You don't mention your exact Unity version
    Also, what about the enemy? How you move it?
     
  3. Pixelnest

    Pixelnest

    Joined:
    Oct 25, 2013
    Posts:
    27
    Hello,

    I updated the post to use the exact current version: 5.3.0f4

    The issue happen with a static or moving enemy.
    When moving this enemy, I use transform.Translate (despite it has a rigidbody, not optimal but once again, it's perfectly fine in 5.1).

    EDIT: the statement above is wrong: I also use the rigidbody2D.velocity to move my enemy.
     
    Last edited: Jan 12, 2016
  4. NicolasHognon

    NicolasHognon

    Joined:
    Nov 15, 2010
    Posts:
    32
    ok ... It is possible the problem comes from the fact you are moving your enemy using transform.Translate and not rigidbod2D.MovePosition or rigidbody2d.velocity. Ok it is working with 5.1 but has you said Physics2D has changed in 5.2 and 5.3.

    I also encounter problem upgrading from 5.1 to 5.2 ...
     
  5. Pixelnest

    Pixelnest

    Joined:
    Oct 25, 2013
    Posts:
    27
    Actually, I checked the code and I am using the rigidbody2d.velocity for the enemy too, I just forgot I dropped Translate few months ago.
    At least wwe are sure about this.
     
  6. NicolasHognon

    NicolasHognon

    Joined:
    Nov 15, 2010
    Posts:
    32
    arg ... no idea ... did you have modified fixedTimeStep ? How is configured your rigidbody2d.interpolation ?
     
  7. Pixelnest

    Pixelnest

    Joined:
    Oct 25, 2013
    Posts:
    27
    I don't recall modifying the fixed Timestep (but so many things can happen in a 20 months project).
    It's current value is 0.02.

    All my rigidobodies2D interpolations are set to None.
     
  8. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    try to update your unity ( it's 5.3.1 now ); there are been some physics related issues fixed in the last patches ( introduced in 5.2 & 5.3 )
     
  9. Pixelnest

    Pixelnest

    Joined:
    Oct 25, 2013
    Posts:
    27
    I'll have a look, but console plugins are tied to very specific Unity version and I can't just update so easily. :/
     
  10. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    what about the patches?
     
  11. Pixelnest

    Pixelnest

    Joined:
    Oct 25, 2013
    Posts:
    27
    Well, I was able to upgrade to 5.3.1p1 without losing console support and the bug is fixed...
    The 5.3.1f1 was a total mess with 150 internal errors/frame.

    It's a bit sad that upgrading can leads to so many bugs.

    Thanks for the help. :)
     
  12. NicolasHognon

    NicolasHognon

    Joined:
    Nov 15, 2010
    Posts:
    32
    the price of success ?