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. Dismiss Notice

Why is my collision so squishy now?

Discussion in '2D' started by Marscaleb, Aug 3, 2018.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    987
    I've had this project that I built in Unity 4.
    Recently I decided to try updating it to the latest version of Unity. I just downloaded version 2018.2.2f1.
    After fixing a couple initial bugs, I've found that now the basic player collision is no longer functioning properly. It's close, but it's turned... squishy.

    I have a sample level built with blocks clearly labeled for how high I should be able to jump and at what point blocks are too high for me to jump on top of. But in this latest version of Unity, sometimes I can jump on top of blocks I should not be able to reach.
    I can see when I jump that I never actually get high enough to clear this block. But if I'm moving when I jump, sometimes I just get pushed up through the geometry. If I hit the edge just right I seem to get pushed up and thus land on top of the block.

    Another thing that keep happening to me is that sometimes if I jump into a wall I will trigger my character's "landed" sequence, and it plays my landing sound and the character pauses for just a moment.
    As best as I can tell, when I hit the wall, sometimes I go into it just a little and it pushes me out, but my points that check if I'm standing on ground get triggered.
    Mathematically, it is impossible for these to get triggered by a wall. They get close to the sides of my player's collision, but they never exceed it. They can't get triggered by a wall unless I'm inside the wall.

    So it seems to me that somewhere between version 4 and version 2018 the collision for 2D objects has become squishy and sometimes objects can intersect one another.
    How do I solve this issue and have solid collision like we used to have?
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    What method are you using to move the player?
     
  3. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    987
    Hmm, I haven't worked with the base movement code for a few years, but it looks like I create a new vector2 for my player's velocity, and then use that in:
    GetComponent<Rigidbody2D>().velocity = newVelocity;

    This occurs within functions called in the Update function.
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Okay, usually when people describe "squishy" physics it's because they are using the transform for movement, and then the position changes are being overridden by the physics system, causing weird overlap behaviors. If you're setting velocity only, you shouldn't have that issue.

    If you turn on Continuous Collision on the rigidbody, does your issue go away?
     
    Thorlar likes this.
  5. reiniat

    reiniat

    Joined:
    Apr 3, 2014
    Posts:
    6
    You shouldnt be updating a Rigidbody on the Update method. Do it in Fixed Update instead.
    If it persists try toying with the interpolation setting on the Rigidbody and continuous collision too.
     
    Thorlar likes this.
  6. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    987
    Looks like my collision wasn't set to continuous.
    I'm not sure if that setting got flipped when I updated to the latest Unity, or if Unity is just handling things differently.

    Changing this has stopped my character from triggering the "landed" function when I bump into walls, but I still seem able to clear jumping heights I previously could not.
    I'm going to try changing all those physics calculations to run inside fixed update; see if that helps.

    EDIT:
    I just put all the movement code into Fixed Update and that didn't seem to have any change. However when I set the interpolate to "none" I can't seem to reproduce the error.
     
    Last edited: Aug 7, 2018