Jump to content

Detect particle collision


Abyss
 Share

Recommended Posts

Hi, babylon js developers! Please help me :).

I want to detect particle collision with camera elipsoid, and when particle will collide - destroy this particle.

Can i make this in particle system update function or how? Babylon js can make this for me?

Link to comment
Share on other sites

If somebody interested, i found one method. In particle system update function i create BABYLON.path3D() between particle position and camera position, now i can calculate distance between this points, and if distance lower then need, just remove this particle.

This method not bad, but in my case, i have to many particles, and performance are very bad. Maybe i should optimize particles, will keep trying.

Link to comment
Share on other sites

creating a Path3D object for each particle test is a little overkill :D

The fastest way would be, imho, to compute in turn the (squared) distance from each particle to the cam ant to compare it to the wanted (squared) distance.

http://doc.babylonjs.com/classes/2.4/Vector3#lengthsquared-rarr-number

something like :

var limit = 10; // your value
var squLimit = limit * limit;
var squDist = 0; // current squared distance
var vector = BABYLON.Vector3.Zero(); // current particle-cam vector

// loop for each particle
...
particle.position.subtractToRef(camera.position, vector); 
squDist = vector.lenghtSquared();

if (squDist < squLimit) {
  // recylce your particle
}

 

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