TheDude Posted August 6, 2015 Share Posted August 6, 2015 How would you go about adding physics int babylon.js? I followed a youtube series by Kris Occhipinti on babylon and got it working but what if you want it to work with imported objects? My code:<script> var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var scene = new BABYLON.Scene(engine); //Physics!!! scene.enablePhysics(); scene.setGravity(new BABYLON.Vector3(0, -10, 0)); var assetsManager = new BABYLON.AssetsManager(scene); var meshTask = assetsManager.addMeshTask("skull task", "", "./", "models/untitled.babylon"); meshTask.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0, friction: 0.5, restitution: 1 }); meshTask.onSuccess = function (task) { task.loadedMeshes[0].position = new BABYLON.Vector3(0, 0, 0); } var Camera = new BABYLON.ArcRotateCamera("Camera", 1, 1, 100, new BABYLON.Vector3(0, 0, 0), scene); scene.activeCamera.attachControl(canvas); assetsManager.onFinish = function (tasks) { engine.runRenderLoop(function () { scene.render(); }); }; assetsManager.load(); window.addEventListener("resize", function () { engine.resize(); }); </script> Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 6, 2015 Share Posted August 6, 2015 Hello, just move mesh.setPhysicState inside the on success function Quote Link to comment Share on other sites More sharing options...
TheDude Posted July 20, 2016 Author Share Posted July 20, 2016 hi @Deltakosh Sorry I never responded, stopped using Babylon.js for awhile (until now!) and for got that I posted this. this works grand! GameMonetize 1 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.