Jump to content

How to point particle system away from mesh?


d13
 Share

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

Link to comment
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 !

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

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

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