Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Collision between BoxCollider2d and PolyhgonCollider2d causes jittering

Discussion in 'Physics' started by leafspring, Jan 2, 2024.

Thread Status:
Not open for further replies.
  1. leafspring

    leafspring

    Joined:
    Aug 26, 2020
    Posts:
    5
    I have a very simple 2D scene where the player character can jump and land on a box. This is done entirely with gravity, so jumping just adds a force and Physics does the rest. There is no manual movement in the code or anything. The player character collider is a BoxCollider2d and a dynamic body, the box is a static body.

    If the object the character lands on is also using a BoxCollider2D then everything is fine. If I change it to a polygon or composite collider, however, the collision becomes unstable and the character jitters endlessly.


    (the static line is the composite collider, the moving one is the box collider from the player character)

    None of the solutions I found so far help (velocity threshold, contact offset). Does anyone have any tips on how to solve this?

    Using Unity 2022.3.3f1
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    This is far from normal and just doing what you're saying you're doing shouldn't produce that i.e. just adding a Rigidbody2D with a BoxCollider2D falling onto a Static shape and not changing any global settings or TimeManager settings etc.

    If you can reproduce this in a new project then can you please zip it up (delete the library folder first) and upload here so I can take a look?
     
    leafspring likes this.
  3. leafspring

    leafspring

    Joined:
    Aug 26, 2020
    Posts:
    5
    Thanks for getting back to me. I tried to reproduce it in a new project but could not. So I went back and looked through my scripts again.

    Turns out it was a kind of race condition with my logic allowing the player to jump through the object from underneath but being able to stand on top. Basically I ended up toggling IgnoreCollisions on and off with every other update respectively... :/

    I didn't find this the first time around because there were so many Google entries for jittering collisions that I defaulted to that as the obvious reason. Sorry for not investigating thoroughly enough before wasting your time.
     
    MelvMay likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    Not a waste of time if you found the issue. Always good to test in isolation! :)
     
Thread Status:
Not open for further replies.