Colliders Sometimes Push Through Each Other

Hi all,

I posted this question last week in the “Editor and general support” section but didn’t receive a response, so I thought I might try here instead. I have two static capsule colliders (without rigidbody components) placed with a small space between them. I have my character with a rigidbody capsule collider that is larger than the small gap between static colliders. Normally, the rigidbody collider will not pass through a static collider, but when two statics are placed with a gap, it seems the rigidbody collider gets pushed through one static collider by the other. What I want to happen is have the rigidbody get stopped and be unable to pass through the small gap.

The colliders are not triggers and I don’t want to substitute one big static collider for the two small statics. Also, the rigidbody collider is not moving at a very high speed. I’ve read previous threads about solving similar issues for fast moving objects, but they apparently impact performance so I’d like to avoid this since this is not a fast moving object.

Here is a screenshot where you can see the small rigidbody collider in the middle is respecting the static collider on the right, but is instead being pushed through the static collider on the left and passing through the barrier:
3250645--250246--Colliders.png

Here is the code I’m using for the movement of the rigidbody collider:

     Vector3 movement;
     Rigidbody rb;
     public float walkSpeed;

     void Awake()
     {
          rb = GetComponent<Rigidbody>();
     }
     void FixedUpdate()
     {
          float h = Input.GetAxisRaw("Horizontal");
          float v = Input.GetAxisRaw("Vertical");
          Move(h, v);
     }
     void Move(float h, float v)
     {
          movement.Set(h, 0f, v);
          movement = movement.normalized * walkSpeed * Time.deltaTime;
          rb.MovePosition(transform.position + movement);
     }

Thanks for the help!

I’m leery of that rb.MovePosition call. I don’t use Unity rigidbodies, but if you’re directly setting the position rather than applying force, or even giving it a velocity, then you might be breaking the collision system by giving it an unstoppable object vs an unmoveable object.

Is there a collision handler anywhere to allow you to stop trying to move in that direction?

Honestly, I’d recommend using forces instead.

No, there’s not. The rigidbody is really only there to detect collisions with static colliders. I don’t really plan on having the character experience physics effects, but I do want him to not walk through colliders.

I agree. I’m pretty sure you want to use forces/velocity to move your player, if that’s what you want.

I’m experiencing the exact same issue. My character’s rigidbody is even passing between two colliders that overlap one another.

I’ll see if I can figure out how to change my movement method to use force and velocity instead too.