Jump to content

Unity Exporter Ground Collisions


MrVR
 Share

Recommended Posts

Hi @MackeyK24 Hey I notice when I export the terrain I get to walk with the universal camera but for spheres and boxes is going through the ground ,  how can I add a mes-collider for the ground so the spheres roll downhill like in your last example ?

 
 var terrain = this.scene.getMeshByName('Terrain');
terrain.checkCollisions = true;
 
But is not working things are going trough the ground, please tell me if know how to get it to work?
Link to comment
Share on other sites

On 3/31/2017 at 6:41 AM, MrVR said:

Hi @MackeyK24 Hey I notice when I export the terrain I get to walk with the universal camera but for spheres and boxes is going through the ground ,  how can I add a mes-collider for the ground so the spheres roll downhill like in your last example ?

 
 var terrain = this.scene.getMeshByName('Terrain');
terrain.checkCollisions = true;
 
But is not working things are going trough the ground, please tell me if know how to get it to work?

checkCollisions is for "Camera Collisions"

I think what you want is physics collision... If you absolutely have to use MESH collision type (which you might have to because i could not get heightMap type to work right)... set Physics Collision to 'Mesh'

 

Link to comment
Share on other sites

Hi guys.  A quick note:  physics meshImpostor is only available on CannonJS engine (not default OimoJS engine), and it only interacts with spheres.

So, to make a BOX tumble on a heightMap terrain, perhaps we could parent 8 tiny invisible spheres to the corners of the box.  Then set sphereImpostors on all 8 corner spheres, and then a boxImpostor on the box itself... IN THAT ORDER (children need their impostors set FIRST in the code, and THEN the parent).

Possibly, NO box impostor on the box itself.  If the sphereImpostors on the corners... overlap the boxImpostor, they could "fight" due to continuous collision of the impostors.  If central boxImpostor IS used, it might be wise to make sure that the 8 invisible spheres are not touching/overlapping the box.

The central boxImpostor would be used... IF, for example, the box tumbled-into a flagpole, and the impact MISSED all the corner impostors (collided at box center).  The central boxImpostor would prevent the physics-active flagpole from passing through the center "volume" of the box.

I think this method... will allow a box to tumble across a meshImpostor heightMap.  Not so easy.  I've never tried it.  :)  Too scared.  heh.

It might be wise to make the entire "tumbling box experiment"... a large-sized scene (if anyone were to try this CannonJS test).  We have seen indications that physics engines don't like tiny things.  SO, if the box-corner spheres were at least size 1, that would be good (perhaps parented to a size 10+ box).

We have also seen indicators that scaling the parent... has issues.  It is better to use BABYLON.MeshBuilder to CREATE the parent mesh... in the exact size needed, and do no after-creation scaling.

This all was a bit off-topic, but, good little secrets to know, when dealing with our two primary 3rd party physics engines.

Link to comment
Share on other sites

8 hours ago, MackeyK24 said:

checkCollisions is for "Camera Collisions"

I think what you want is physics collision... If you absolutely have to use MESH collision type (which you might have to because i could not get heightMap type to work right)... set Physics Collision to 'Mesh'

 

Hi @MackeyK24 I did try to put a mesh collider into the terrain but is not working I get an error

 

meshCollider.JPG.71ea115f57345234e26836a9581cb6ba.JPGmeshcollider2.JPG.20a812a58de9f625669fca1d2ff220d3.JPG

 

I ALSO TRIED with no luck let me know if you see what I'm missing here 

 

 public start() :void {
          let terrain =  this.scene.getMeshByName('Terrain');
          terrain.checkCollisions = true;      
          terrain.setPhysicsState({impostor:BABYLON.PhysicsEngine.MeshImpostor, move:false, mass:0, friction:0.5, restitution:0.1});
        }

 

Edited by MrVR
Link to comment
Share on other sites

1 hour ago, MrVR said:

Hi @MackeyK24 I did try to put a mesh collider into the terrain but is not working I get an error

 

meshCollider.JPG.71ea115f57345234e26836a9581cb6ba.JPGmeshcollider2.JPG.20a812a58de9f625669fca1d2ff220d3.JPG

 

I ALSO TRIED with no luck let me know if you see what I'm missing here 

 


 public start() :void {
          let terrain =  this.scene.getMeshByName('Terrain');
          terrain.checkCollisions = true;      
          terrain.setPhysicsState({impostor:BABYLON.PhysicsEngine.MeshImpostor, move:false, mass:0, friction:0.5, restitution:0.1});
        }

 

 This duplicates what the the toolkit does... Dunno maybe let me check out your scene

Link to comment
Share on other sites

1 hour ago, MrVR said:

May be this tutorial from Raanan show what you are  tell me I think about the sphere impostors 

https://blog.raananweber.com/2016/04/03/cloth-physics-simulation-for-babylon-js/

 Well this is manually creating several physics imposters (which you still can do with the toolkit.. just DONT use a physics state component and handle like you normally would with regular BJS code)

Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...