Sign in to follow this  

Detect particle collision

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?

Share this post

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

Share this post

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

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


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.