Unexpected collision behavior

I try to make a simple 2D game, where the collision is handled by simple shapes. This is why I thought, that it wouldn’t be necessary to use a custom physics-engine and went with the default one.

I set up a simple playground just containing a collision box and a smaller box with input-controls: Babylon.js Playground

After reading about collision in the documentation, I think the moveWithCollisions function is what I need, but the result differs from what I expected in two ways:

  1. when moving closely around the corners of the big box, the player moves in a circular way and not like it is moving around a corner. (even if the player is a cube)

  2. when trying to touch the wall with the long side of the player, it always stops with some distance. (this is not the case, if the player is a cube)

Did I do something wrong, do I have to use a custom physics engine or is there some easy way to get it working?

This is all normal and expected as moveWithCollision is meant to be only representing ellipsoid shapes: Camera Collisions | Babylon.js Documentation

This playground from our friend @Wingnut might be helpfull:

All based on the mesh intersections so you can have fine control: Mesh Intersections | Babylon.js Documentation

3 Likes