Jump to content

ApplyGravity on mesh


Recommended Posts

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;}
Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...