# 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?

##### 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 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 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:

##### Share on other sites

Here's a playground with a simplified version of the problem:

(I can reproduce the bunching-up effect if I use `ps.direction1 = -vectorSunToMoon`)

##### 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);``````

##### Share on other sites

ps.lookAt(sun.position)
?
Not sure if that will work or not.

##### Share on other sites

`lookAt` not a function

.... oh... but it does work if I use lookAt on the emitter!

##### Share on other sites

You have to update the direction, as it changes when the particle system/emitter moves.

http://www.babylonjs-playground.com/#1UGDQC#23

##### 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!!!!