Sign in to follow this  
TheDude

How to set up physics for .babylon file in js

Recommended Posts

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>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.