Sign in to follow this  
Panuchka

Removing the physics collisions after mesh removal

Recommended Posts

Hi, just a short question about physics usage. I use Cannon.js for now, moving to Oimo.js later on.

Anyways, I'm making a Bomberman clone with physics turned on. Let's say that I have a 20 x 20 grid. Bomb explodes in my game and this should destroy some random tile. After I dispose the mesh, the physics impostor seems to be there still, since my trusty old debug ball happily rolls over the empty space.

The question is: How to remove mesh and its physics properties from the scene?

Share this post


Link to post
Share on other sites

Here you go sir! 

http://www.babylonjs-playground.com/#BHMRT

Although I've been thinking of maybe dumping the use of physics engine and just use the collisions. What would I miss? If the only thing I need is some falling from the platforms, it is probably wiser to use something simpler? 

I'm curious, have you investigated how much the physics engine slows down everything?

Share this post


Link to post
Share on other sites

I managed to fix it. The problem was that I did not assign the physics impostor to the mesh properly:
 

// RIGHT
tileMeshCopy.physicsImpostor = new BABYLON.PhysicsImpostor(tileMeshCopy, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 0.9 }, scene);

// WRONG
new BABYLON.PhysicsImpostor(tileMeshCopy, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 0.9 }, scene);


Here is the working one:
http://www.babylonjs-playground.com/#BHMRT#1

I kind of thought that just creating the physics impostor would attach it to the mesh itself. Oh well :D 

Share this post


Link to post
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.

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

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.