Search Unity

Question Movement is horrible when moving a capsule over multiple box colliders. What are my options?

Discussion in 'Physics' started by funkyCoty, Sep 2, 2020.

  1. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    Hey there. I've got a simple example video of what I'm referring to.


    (mirror, https://uploads.coty.tips/OdfLKpWgmn.mp4)

    When my player (capsule collider) uses RigidBody.AddForce( new Vector3(0, 0, 1) ), with friction set to 0, and drag very low, just straight forward, on most surfaces it will smoothly move along the surface. However, if the surface happens to be made of multiple Box colliders (or even multiple mesh colliders), the transition from one collider to the next results in this BUMP. It's a very large bump, sometimes several meters into the air.

    The most obvious solution is to simply turn up Default Solver Iterations and Default Solver Velocity Iterations. This does mostly fix it, however I cannot use this solution due to the target hardware's processing limitations, the hit becomes an unrealistically high chunk of the frame time.

    My next guess is to try and merge colliders. I was hoping making them a compound collider would fix this, but it does not. Is manually building a mesh collider my only option, in this scenario? The level here is procedural, so the solution would need to work at runtime, outside of the Unity Editor.

    Any ideas or solutions? Thanks.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Try reducing Default Contact Offset in Project Settings > Physics.

    You may also try specifying a value in Rigidbody.maxDepenetrationVelocity, which is Infinity by default. Something between 2 and 10 m/s should suffice.
     
  3. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    I've tried setting default contact offset to a very low value (0.00001) and maxDepenetrationVelocity to 0.01, and the result looks the same :(
     
  4. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    Changing the collision detection mode seems to have a huge impact.



    However, Unity is still reporting collisions, and there are still smaller bumps.
     
    Last edited: Sep 2, 2020
  5. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    This is a problem and has been for many years.

    do you need dynamic capsule colliders? Character controllers don’t suffer this problem. There are some better character controllers than the default one available on the asset store too.

    if you can’t use character controllers then another option it to make the ground have zero bounce in its physics material and be sure to set the bounce calculation method to min on your capsule collider as well.

    for my minigolf game i have two colliders for the ball. A no bounce collider that collides with the ground and a full bounce collider that collides with everything else. It solves the ground bumps but you still get odd collision hitting joins in straight walls etc. another problem with this method is if the capsule falls and lands on a join in the ground then it may suddenly stop or change direction, however I think this may already happen with your current setup as well.

    Finally you may also be able to try havok physics. I believe there is an option in havok to combine collider meshes at runtime automatically as well as weld the verts. I only saw it written somewhere and have not tried it myself so I’m not sure how to do it or how effective it is at solving this issue.
     
    Last edited: Sep 2, 2020