Hi there,
Context: I am developing a third person platformer game where the player can move a mesh using the WASD keys. I use the moveWithCollisions() function on the mesh and the internal collision system to handle all collision with objects. My game includes player crouching/standing on a button press, which I’ve solved by disposing the mesh with mesh.dispose() and re-creating it in a different shape.
Bug: Usually, whenever I press my mesh into an angled shape (like a tilted box), the collision handling works as expected, meaning the mesh more or less stays at the same vertical position, and doesn’t sink into the ground. However, after dispoing the mesh and re-creating it, the collision system is acting very strange. If I move my mesh back into the angled shape, the mesh now sinks into the ground. Strange, huh?
I have tried to run my code on several versions of babylonjs, including the newest 5.0.0, but the bug still persists.
Playground link to reproduce: https://playground.babylonjs.com/#KBS9I5#2192
Steps to re-produce bug:
- With WASD, move the player (cylinder) into the angled box straight ahead
Notice how the collision system prevents us from sinking into the ground - Press ‘Space’ to trigger mesh.dispose() and re-create the player mesh
- Move the player back into the angled box and notice how the cylinder
now sinks into the ground when moving it repeatedly.
Additional notes: The bug doesn’t occur if I use mesh.setEnabled(false) instead of mesh.dispose(). Furthermore, I tried messing around a bit, and for some reason the bug does not occur if I dispose of a random box before disposing of (and re-creating) the mesh. So weird.
For now I chose to fix this issue by creating the two different meshes I need initially and then switch between them using the setEnabled function, but I’m still incredibly curious what could be triggering this bug.