Jump to content

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

  • 11 months later...

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...