0
\$\begingroup\$

Consider this simple scene: enter image description here

In Unity, colliders slightly intersect each other. Typically, this isn't a problem. However, I want to make a custom character controller using a box collider and not a capsule collider. In the above scene, the floor is divided into 2 objects, each with their own collider. The playercontroller has their own box collider.

And the problem: if the box collider moves forward, it will clip with the seam on the floor, even though both floor objects have the same height. The box will stop moving as if it has run into a wall. If I keep adding force to the box, it will never move forward. It will stay stuck on the seam-- this only exists because the box is slightly inside the first floor collider, and it will hit the second collider of the floor like a wall.

This only occurs because of collisions clipping. With most playercontrollers, a capsule collider is used and thus this problem doesn't exist.

Is there a workaround? How can the box smoothly move across the floor without colliding with the seam?

Notes:

  • This does occur with capsule colliders but rare and is not very noticeable.
  • A possible solution would be to merge all the colliders of the scene into one, unified collider. It is extremely tedious and has its drawbacks.
  • This occurs if I am moving the collider with both MovePosition(), AddForce(), or modifying the velocity/position of the transform.
\$\endgroup\$
2
  • \$\begingroup\$ You might find past Q&A about dealing with this useful. Bennett Foddy talks about this and other common physics engine quirks, why they work the way they do, and ways to work around them in this GDC talk. \$\endgroup\$ – DMGregory Mar 26 '20 at 10:28
  • \$\begingroup\$ I've seen that video a while back; there just doesn't seem to be a solution. The only possible solution I can see is entirely blocking collision with a certain face, but Unity doesn't allow that. \$\endgroup\$ – blackhole Mar 26 '20 at 17:16
0
\$\begingroup\$

the box is slightly inside the first floor collider

Is this on purpose? If not, it's not the best solution but maybe you can increase the height of the box just by a bit, enough to make it "float" above the floors and not collide with the seam, but not too much to be noticeable while viewing the scene.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.