1
votes

I'm using a terrain in Unity 2019.2.1f1 and a custom mesh of a cave with a mesh collider.

My character that has a Capsule Collider way bigger than the entry of the cave should not be able to enter in. But due to the roundness of both colliders, he can come into force in the cave, glitching through the terrain collider.

I think it's velocity is not excessive, I'm moving the character with rb.MovePosition() in the FixedUpdate(), and I set its rigidbody collision detection to Continuous speculative (tried all the "continuous" modes)

In the animation below, you can see the mesh of the cave and the capsule collider around the character.

How can I prevent this from happening? How can I say to Unity: "I want the colliders to be rock solid and not marshmallow"?

collider_glitch

1
Try using rb.AddForce instead of rb.MovePositionRuzihm
Thank you, I wanted to use MovePosition but since this problem, I think I will use a mix of AddForce and RootMotion (thanks to the OnAnimatorMove() callback).Maarti

1 Answers

3
votes

Colliders in Unity are rock-solid. They are incapable of any kind of soft physics, and the only moment they will warp through each other is when you force them to.

Here, you are setting the rigidBody position by force, into an impossible location. The game tries its best to fit your rigidBody despite the lack of room.

You can

  • Only use forces, and velocities. You can simply set the velocity to the direction of your choosing, and set it to 0 when you stop moving, or use AddForce, which is basically the same thing.

  • Keep using MovePosition, but use a SphereCast or CapsuleCast to check if you have enough room to move first.