Prevent camera jittering depending on gravity amount

Hi,

I’m trying to move a camera around as you would in an FPS game.
I’m using ground created from a heightmap, on which I correct the camera’s Y position instead of using actual collision detection with the ground (the latter drops framerate considerably on larger meshes).
This works fine, except if I reduce the gravity in the scene - this causes the camera to ‘jitter’ on the Y axis:

https://playground.babylonjs.com/#FUN65H#5

I need to reduce the gravity for jumping to be possible.
Is there a way to fix the jitter on the Y-axis with lower gravity settings?

(note: if you set the gravity to -5 or so, the jitter stops)

Hi Censor,

Have you tried moving the camera by calling moveWithCollisions Instead of setting the position directly? For your jumping behavior, you could use an isJumping flag that, while true, disables or lowers gravity until it reaches some condition.

You can have a look at this example - https://playground.babylonjs.com/#NT4QZ8#7
Also note, that for jumping you may not need to change the gravity, it is enough just to move camera up.

1 Like

Thank you for your replies.
@jelster I haven’t tried that, but the reason I’m trying to avoid using the collisions against terrain is because it is a lot faster I believe:

@labris thanks for the link, I have seen it before, but when I make the terrain more complex / larger, the frames drop a lot:
https://playground.babylonjs.com/#NT4QZ8#112

@jelster, I read over your suggestion to adjust gravity while jumping, I’ll give that a shot.

Ok so pretty dumb but I just figured out my check and set for cam’s pos y was incorrect.
Fixed it and no problems now.
https://playground.babylonjs.com/#FUN65H#6