moveWithCollisions not working when changing y rotation of mesh

Hi guys, I need your help, I haven’t known for a week why moveWithCollisions doesn’t work when the mesh (wall) is in a y axis specific rotation.
This is the repo and I hope you can help me, Thanks.
To test the bug they must try to go through the red walls.

Hello @gaston_pedraza , how are you doing? Welcome to the babylon.js community!

I took the example you gave and placed it on a Playground, so it is easier for us to reference it.

Babylon.js Playground (babylonjs-playground.com)

From what I can see in the behavior the player seems to be colliding with the walls, but it gets stuck, is that the issue?

yes, that is the issue. Thanks for putting the example on the playground.

By default, Babylon.JS will check for collisions using a complex algorithm that checks collisions per triangle on the mesh. This might lead to incorrect behavior when objects are moving fast and colliding. I think a good solution might be to use a BoxCollider on your player and check the collision using that, instead of the mesh, this should give you more reliable results.

The method would consist on:

  • Create by code a new cube mesh or sphere mesh (named collider)
  • Add the collider as a child of the mesh
  • Apply the bounding box properties of the mesh to the collider
  • Disable collisions on the mesh and enable collisions on the collider.

Documentation:
Advanced Collisions | Babylon.js Documentation (babylonjs.com)

Some reference example:
Compound Bodies | Babylon.js Documentation (babylonjs.com)

Let me know if you need any extra help with that.

1 Like

Thanks for your responde, I am new in babylon and I can’t reply your solution. Could you show some example on the playground?

Hey @gaston_pedraza , here is a playground example with the implementation:

Babylon.js Playground (babylonjs-playground.com)

I created a invisible capsule mesh and added your character as a child of that, this way you can use moveWithCollisions on the capsule object which should give you way better results.