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

Bug Unity 6 Physics2D

Discussion in '2D' started by BACALL, May 13, 2024.

  1. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    90
    I am testing my project in Unity 6, and I'm having issues with the 2D physics. Tthe Player can crouch, while crouching his capsule collider gets smaller (so he can fit through holes, or avoid bullets). But since updating, when crouching he can sometimes go through walls or the floor. This never happened before.
    Setting the “Contact Threshold” from "0.01" to "0.001" helped a bit, but setting it lower won’t help. He’s still going through some walls and floor. Other times he's not...

    I am using a SpriteShape as ground with a PolygonCollider2D.

    Changing the Capsule Collider like this (nothing fancy):
    Code (CSharp):
    1.         CapsuleCollider.size = crouchCapsuleSize;
    2.         CapsuleCollider.offset = crouchCapsuleOffset;
    Moving the player has a long and convoluted script, but in the end I'm simply setting his velocity (worked in earlier Unity 2D projects without making him fall through the floor):
    Code (CSharp):
    1. private void SetVelocity(Vector3 target) => Rb2D.velocity = target;
    It looks like he falls through the cracks (see the gif and also the image with the SpriteShape PolygonCollider2D visible). This can happen on any green line/polygon intersection, or whatever you call it, on the SpriteShape.

     
    Last edited: May 13, 2024
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,692
    I apologise, there was a bug introduced in 6000.0.1 however it has been fixed and hoping it'll land in 6000.0.2. I'll report back here if it doesn't in which case it'll land in 6000.0.3.

    For now, simply set the ContactThreshold to 0 to turn this feature off and it'll fix the issue. You can restore it to its default of "0.01".

    See here about when it's not used:
    https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Physics2D-contactThreshold.html

    Again, sorry for the issue.
     
    BACALL and Spy-Master like this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,692
    The fix for this has just landed in 6000.0.3f1 which is scheduled for release May 22nd - 24th.

    Again, sorry for the issue.
     
    BACALL and spiney199 like this.
  4. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    90
    No worries, glad to hear a fix is on the way, thank you for the quick reply!
     
    MelvMay likes this.
  5. alexennerfelt

    alexennerfelt

    Joined:
    Jan 7, 2017
    Posts:
    21
    I'm having similar issues with Physics 2D in Unity 6 where collision detection is not handled properly. I'm on 6000.0.4f1 and I am having these issues.

    It doesn't matter if the collision detection is Discrete or Continuous, Interpolated or Extrapolated. My Character will now pass through any collider if it is moving fast enough (on dashing for example)
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,692
    Nothing else has changed and the above feature doesn't apply when using Discrete so this thread is unrelated and you have another issue.

    Interpolation/Extrapolation are nothing to do with collision detection. They are a Transform thing for visuals only and do not affect physics at all.

    I would recommend creating your own thread and posting some details of what you're doing.