How to avoid moveWithCollisions shaking when gravity is applied?

Is there a way to avoid moveWithCollisions() shaking when gravity is applied?
This is how it looks: Playground

And one more little question. Why do I have NaN in this case?

const move = player.forward.scaleInPlace( 0.5 ).addInPlace( 0, 0, 0 );
console.log( `move = ${ move.toString() }`); // move = {X: NaN Y: NaN Z: NaN}

To your little question I can say you don’t pass a BABYLON.Vector3. You just passed 3 numbers.

Code:

const move = player.forward.scaleInPlace( 0.5 ).addInPlace( new BABYLON.Vector3(0, 0, 0) );

Also consider InPlace changes your applied vector, in this case player.forward. I am not sure if you intend to do so. It would add up like acceleration.

I expanded your playground by engine.getDeltaTime, which is the time between now and last rendered frame, correct me if I’m wrong here, and smaller velocity vector:

1 Like

I see you’ve just scaled down the forward speed that’s why it has stopped from shaking. But what if we need to deal with faster speed? Like this one: https://playground.babylonjs.com/#6EU8HW#5

I assume with this high velocity the player would partly pass the mesh in a render frame and so stutters.

Increasing depth of ellipsoid works:

player.ellipsoid = new BABYLON.Vector3( 0.6, 0.98, 1.2 );

Or increase mesh size:

box.scaling = box.scaling.scale(2);

Edit: What I forgot is to apply deltaTime to velocity, I guess you need to decide if you need it or not.

3 Likes