Camera gravity doesn't work with Cannon

Hello.
I am trying to apply gravity to my UniversalCamera but it doesn’t seem to work. Nothing happens, the camera is static, and there is no error either. I am using the latest cannon.js version.

This is my code:


var canvas = document.getElementById('game');
var engine = new BABYLON.Engine(canvas);
var scene = new BABYLON.Scene(engine);
scene.enablePhysics(new BABYLON.Vector3(0,-10, 0), new BABYLON.CannonJSPlugin());
scene.collisionsEnabled = true;
var cube = BABYLON.Mesh.CreateBox("box", 4, scene);
cube.applyGravity = false;
var camera = new BABYLON.UniversalCamera('pplCam', new BABYLON.Vector3(-10, 20, -10), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl(canvas, true);
camera.applyGravity = true;
camera.checkCollisions = true;
camera.ellipsoid = new BABYLON.Vector3(4.8, 3, 4.8);  
var light = new BABYLON.HemisphericLight("Sun", new BABYLON.Vector3.Zero(), scene);

engine.runRenderLoop(function(){
    scene.render();
});

Am I doing something wrong?

I just realized the gravity only works when movement is applied, so based on another topic, I had to use camera._needMoveForGravity = true;
Thanks all

1 Like