Collision Capsule and Camera Height Issues

In this example, I want to rely on gravity with collision capsules to constrain the camera to the ground.
But because of the collision capsule, it prevented me from squatting in the VR mode headset.
To solve this problem, I tried setting the dynamic capsule height dynamically.
See line 96 of the code.
When you change 0.49751244017146684 to another value, the height of the collision capsule accumulates or decreases as the camera moves.
I would like to know why its value is not 0.5 but 0.49751244017146684, can anyone answer for me. :thinking:

Feels like a javascript floating point arithmetic precision issue. When you say “when the camera moves” , do you mean the movement WebXR feature?
Can I ask - how did you get this wonderful value? I mean, why not 0.49? or 0.497?


See here, moving the xrCamera with the joystick, he will change position.y under the influence of gravity and collision capsule, and this console outputs a value of 0.49751244017146684 when position.y no longer changes.

This is because of javascript’s math precision. Sadly no way around it. You will simply need to compensate correctly. I would assume 0.4975 would work the same.
It is a combination of different matrix computations, inversions, and two babylon components (the collision system and the movement support for webxr).
Maybe using a physics engine instead would provide you with better experience, instead of the internal collision system

This problem is not limited to webxr, pc mode cameras have the same problem and the value changes depending on the ellipsoid shape. For me at the moment, hardcoding 0.4975124 solves the problem.


My guess is that there is a problem with calculating collisions like in the picture. :grin: