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.

Bug Capsule collider clipping through ground when landing and then bouncing back

Discussion in 'Physics' started by rjcortes, Mar 11, 2023.

  1. rjcortes

    rjcortes

    Joined:
    Jul 21, 2020
    Posts:
    1
    Hi all, I couldn't find anyone else who had the exact same problem as this so I'll try my luck here. Like the title says, I have a capsule collider for my player with a dynamic rigidbody attached, and about 10% of the time when I land on a platform (box collider, no rigidbody), the capsule collider clips through the platform and will pop back on top of the platform over the next 3-5 frames. Something else I've noticed is that the clipping seems to be direction dependent, so if a specific velocity causes clipping it will do so every single time.

    This obviously happens the most when the collision detection of the rigidbody is in Discrete mode, but it also happens when in Continuous mode. I've found that using Continuous Speculative appears to solve the issue, but I'd like to understand why that is? From what I understand with Continuous, it should prevent any clipping because of how it sweeps the collider between frames. Anyone have any insight into this? I have a feeling it must be some quirk of the Unity Physics Engine that I'm definitely not equipped to figure out on my own.
    Clipping_issue.png
     
  2. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    445
    It is true that CCD (continuous) doesn't prevent the character from going into the ground for a few frames.
    Example:
    left = CCD, right = DCD, yellow = floor, red = rbs + gravity
    upload_2023-3-15_2-4-21.png

    After doing a little search, I found this on the Physx's CCD documentation page:
    "Once enabled, CCD only activates between shapes whose relative speeds are above the sum of their respective CCD velocity thresholds. These velocity thresholds are automatically calculated based on the shape's properties and support non-uniform scales."

    Just for fun, If i change the floor height this happens (same example):
    upload_2023-3-15_2-12-13.png

    Maybe because it performs speculative CCD all the time (?)
     

    Attached Files:

    rjcortes likes this.