# ApplyGravity on mesh

## Recommended Posts

Hi,

I trying to create a similar game for learn BabylonJS. I want to create a short game with dynamic objects. I can set the gravity to scene and camera but I can't to any meshes.

So camera.applyGravity = true; working fine, but box.applyGravity = true; is ignored. My box still as a static mesh, gravity has no effect to the box.

Is it possible to implement gravity on meshes? Am I on the bad way?

My scene code below:

`var createScene = function (engine) {    //Creation of the scene    var scene = new BABYLON.Scene(engine);    //Adding of the light on the scene    var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 100, 100), scene);    //Adding of the Arc Rotate Camera    //var camera = new BABYLON.ArcRotateCamera("Camera", 0, 1, 100, new BABYLON.Vector3.Zero(), scene);    var camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, 10, -20), scene);    var box = BABYLON.Mesh.CreateBox("Box", 6.0, scene);    box.position = new BABYLON.Vector3(0, 20, 0);    var ground = BABYLON.Mesh.CreatePlane("Plane", 50.0, scene);    ground.rotation.x = Math.PI/2;    ground.position = new BABYLON.Vector3(0, 0, 0);    //COLLISIONS BY GRAVITY    //---------------------    //Set gravity to the scene (G force like, on Y-axis. Very low here, welcome on moon)    scene.gravity = new BABYLON.Vector3(0, -1, 0);    // Enable Collisions    scene.collisionsEnabled = true;    //Then apply collisions and gravity to the active camera    camera.checkCollisions = true;    camera.applyGravity = true;    //Set the ellipsoid around the camera (e.g. your player's size)    //camera.ellipsoid = new BABYLON.Vector3(1, 1, 1);    box.checkCollisions = true;    box.applyGravity = true;    //finally, say which mesh will be collisionable    ground.checkCollisions = true;    return scene;}`
##### Share on other sites

You code is good but right now we are only supporting collisions between the avatar of the camera (an ellipsoid) and the world.

We are working right now on integrating cannonjs to support physics between meshes Stay tuned so^^

##### Share on other sites

Oh, I see. But integrating cannonjs is a really good news. Thanks for the quick answer.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.