Jump to content

Collision detection


yorke
 Share

Recommended Posts

Hi all, my first post here.

I'm learning babylon.js after having worked in three.js and I must say that I love this framework, many thanks to its creators for such a professional production.

Actually I'm experiencing a little problem with collision detection between particles "fired" from a SolidParticleSystem and a mesh: I can trigger the collision between the particle and the mesh using

particle.intersectsMesh(window.engine.scenes[0].meshes[15])

but intersectMesh() seems to become true when collision occurs with mesh's BoundingBox, which is way too approximate when I use a human mesh.

Is there a way to calculate the exact point of collision from particle to mesh?

I thought i could fire a BABYLON.Ray when intersectMesh() becomes true and retrieve the "real" intersection with mesh, is this a good approach or you think it can be done better? Are there any examples of using Babylon.Ray to retrieve exact intersection with a mesh?

Thanks to all :)

 

Link to comment
Share on other sites

http://doc.babylonjs.com/overviews/solid_particle_system#particle-intersections

you could test with the intersectsMesh() method from the AbstractMesh class by forcing the precise mode :

yourMesh.intersectsMesh(theParticle, true);

Note well, that testing against OBB (oriented bounding boxes) will be done only for the mesh (the particle BBox will keep axis aligned) and that this kind of test needs really more CPU.

Testing with Ray is another option... and requires even more CPU.

Link to comment
Share on other sites

Thanks for your kind suggestions, i'll give it a try this evening and report the results.

I've another question on the same subject (collision between solid particle and mesh): are there any functions that can give you the normal of the mesh face hit by the particle?

I mean: I surely know the vector that gives me the direction of the particle bullet, but no one grants me that the mesh face hit is normal to that vector (e.g. a sideswiped mesh).

Many thanks yet!

Link to comment
Share on other sites

Tnx jerome, I just saw some playgrounds of yours about facets and collision and they're really impressive.

So let me understand better:

With:

yourMesh.intersectsMesh(theParticle, true);

I have the coordinates of the impact point on the mesh, that come from the particle coordinates.

How can I use this coordinate to retrieve the mesh's hit facet index inside the mesh tree structure?

Link to comment
Share on other sites

intersectsMesh() just returns a boolean. You can't get the intersection point from it.

The only way I know to get the facet id (or index) is to use either a PickingInfo object, either the facetData provided functions

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