d13

How to point particle system away from mesh?

Recommended Posts

Hi Everyone!

I'm working on a solar system model and am currently trying to create an accurate-ish simulation of Halley's Comet.

The comet tail aways points away from then sun. So, I have a two part question for any experienced users out there:

1. How can I obtain the vector between 2 meshes (in this case Halley's Comet and the Sun)?

2. Which properties do I need to set in the ParticleSystem object to make the particles emit in the direction of that vector?

Screen Shot 2018-01-10 at 8.44.23 AM.png

Share this post


Link to post
Share on other sites

To get the distance between two points:

let distance = BABYLON.Vector2.Distance(Vector2: sun.position, Vector2: target.position);        
return distance;

Share this post


Link to post
Share on other sites

Hi d13 !

1) use position property of mesh (Vector3) to compute it. 
var vectorSunToHalley = halley.position.subtract(sun.position);

2) You can find info about particles here : https://doc.babylonjs.com/babylon101/particles
Particles emission's direction is given by the two properties direction1 and direction2

Need to see your project once it's finished ! Looks beautiful !

Share this post


Link to post
Share on other sites

 

Thanks @Amarth2Estel!

Obtaining the vector between the sun and valley's comet works!

But I'm not sure how to apply that vector to the comet tail emitter

let vectorSunToHalley = halleysComet.position.subtract(sun.position);
cometTail.direction1 = vectorSunToHalley

Does that seem like it should work?

In my program it has the result of bunching the particles up into a cube:

 

Screen Shot 2018-01-10 at 10.48.34 AM.png

Share this post


Link to post
Share on other sites

This effect works pretty well, I just have to find out how to orient the tail away from the sun:

cometTail.direction1 = new BABYLON.Vector3(-4, -8, 3);
cometTail.direction2 = new BABYLON.Vector3(4, -8, -3);

 

Screen Shot 2018-01-10 at 2.30.00 PM.png

Share this post


Link to post
Share on other sites

@aWeirdo Awesome, that works!!

I hadn't considered updating the direction... and normalizing it!

 

I also got it working by using `halleysComet.lookAt(sun)` in the update function (`halleysComet` is the emitter), and by initializing the `cometTail` particle system with this direction:

  cometTail.direction1 = new BABYLON.Vector3(3, 2, 16);
  cometTail.direction2 = new BABYLON.Vector3(-3, -2, 16);

Now it always points away from the sun.

Thanks so much everyone!!!!

 

Screen Shot 2018-01-10 at 3.28.32 PM.png

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

  • Recently Browsing   0 members

    No registered users viewing this page.