Threedy Posted January 17, 2016 Share Posted January 17, 2016 Edit: Problem fixed. After some experimenting, I realized that the gravity should be passed like this: world.gravity = vector. Hi, I have the following simple example from the wiki page of Cannon JS... I expected the ball to fall, but it didn't and only prints ''Sphere position: 0,100,10''. Can anyone understand why? I then thought (based from the wiki) that I had to use Rigidbody (CANNON.RigidBody) but that wasn't recognized. Any tip is greatly appreciated. Quote // Setup our world var world = new CANNON.World({ gravity: new CANNON.Vec3(0, -10,0) // m/s² }); // Create a sphere var radius = 1; // m var sphereBody = new CANNON.Body({ mass: 5, // kg position: new CANNON.Vec3(0, 100, 10), // m shape: new CANNON.Sphere(radius) }); world.addBody(sphereBody); // Create a plane var groundBody = new CANNON.Body({ mass: 0 // mass == 0 makes the body static }); var groundShape = new CANNON.Plane(); groundBody.addShape(groundShape); world.addBody(groundBody); var fixedTimeStep = 1.0 / 60.0; // seconds var maxSubSteps = 3; // Start the simulation loop var lastTime; (function simloop(time){ requestAnimationFrame(simloop); if(lastTime !== undefined){ var dt = (time - lastTime) / 1000; world.step(fixedTimeStep, dt, maxSubSteps); } console.log("Sphere position: " + sphereBody.position); lastTime = time; })(); Quote Link to comment Share on other sites More sharing options...
schteppe Posted February 11, 2016 Share Posted February 11, 2016 Which Cannon version ? Can you give a direct link to where you found the old RigidBody class? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.