Pressing 'down' or 'up' has mesh go 'up' either way + ground collision appears to be prematurely detected

Hello :smiley: :waving_hand: ,

While trying to implement a character controller based on movewithCollisions I’m having troubles having my controlled mesh properly moving up and down, along the scene’s Y axis.

I have no trouble (so far) translating the mesh within the horizontal plane or rotating it around its Y axis. Hence the provided example Babylon.js Playground only deals with translating the mesh vertically (My purpose is to eventually implement some ‘jump action’ without relying on plugins and impostors, but found out I couldn’t even implement a basic vertical translation yet :smiling_face_with_tear:).

The mesh is expected to move up when ‘q’ is pressed and down when ‘a’ is pressed. However:

  1. At first both keys result in an upward movement when pressed. (:thinking:)
  2. At some point going up the position increment seem to increase drastically compared to the first few key presses. (:exclamation_question_mark: :upside_down_face: - maybe I’m mutating the ‘up vector’ but my modest investigations suggest otherwise, logging said ‘up vector’ over time, using Vector3.Up() or brand new Vector3 instances instead…)
  3. Once ‘up enough’ I’m able to move the mesh down although it stops way before actually colliding with the ground (about half my box’s size it seems) for no apparent reason as far as I can tell. (:crystal_ball: :upside_down_face:)

I’m pretty sure I had obtained the expected behaviour rather trivially through previous experiments so I’m probably missing something very obvious (though not to me at the moment :smile:) here.

Thanks in advance for reading this :folded_hands:

Best regards :smiling_face: ,

It’s PG regarding the solution

The overall issue is that the size of the collision was larger than the actual box, and as a result, the collision was caught in the collision within the ground. The cause is that the ground has only one surface, so it tries to process the collision by going from the non-existent surface to the surface with the collision.

If the player is a sphere, it seems like it would be solved by having half the volume.

1 Like

Thank you very much for your answer and the provided PG :smiling_face:

Yes, the box’s ellipsoid was taller than its mesh, that was the essence of it !

I see now that regardless of the initial mesh dimensions the default ellipsoid dimensions are defined like so: { x: 0.5, y: 1, z: 0.5} (and indeed the y should be halved in my case). Thus, tweaking the mesh’s ellipsoid dimensions to match the mesh’s seem to be working while still using a ground created by MeshBuilder.CreateGround (and it seems to help me with the part of the issue related to ‘collision need double side’ as well).

Thanks a lot again :smiley: :folded_hands:

1 Like