# How to assign gravity of particles based on mesh emitter position/vector(not world)

**URL:** <https://forum.babylonjs.com/t/how-to-assign-gravity-of-particles-based-on-mesh-emitter-position-vector-not-world/53584>\
**Category:** Questions\
**Tags:** particles\
**Created:** [September 20, 2024, 4:43am UTC](https://forum.babylonjs.com/t/how-to-assign-gravity-of-particles-based-on-mesh-emitter-position-vector-not-world/53584 "2024-09-20T04:43:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TooCalm](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/toocalm/32/3301_2.png) [@TooCalm](https://forum.babylonjs.com/u/TooCalm)\
**Post date:** [September 20, 2024, 4:43am UTC](https://forum.babylonjs.com/t/how-to-assign-gravity-of-particles-based-on-mesh-emitter-position-vector-not-world/53584/1 "2024-09-20T04:43:52Z")

</div>

Hey guys,

> **[Babylon.js Playground](https://playground.babylonjs.com/#PU4WYI%23478)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

use this demo with such parameters:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/f/ffbc3be8c4fd3effc9e0297ecd4b4eb87fcf60f0.jpeg)  
i enabled gravity for those particles and it works perfect except of a problem. it’s usable only for static objects like bonfire where we always know that direction of particles will be up.

I need to create directional particles for movable object. and particles should have direction based on direction of mesh (for example i want to create tail with fire on the end of it) i can’t use gravity for this because gravity is a static direction.

i found that i can enable isLocal parameter for particles. in that case it works perfect for tail but i have another problem. There is no shlave of particles. it looks unnatural. To see what i mean try to uncomment 37line of code and use next parameters

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/0/302d03ead57ffaf05e793bba72a468bc8313ecc1.jpeg)

Final perfect result for me is particles assigned to mesh with dynamic direction of mesh and shlave. is there any way to do this without writing some custom functions which calculates gravity vector and assign it each tick?

Thanks

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [September 20, 2024, 11:25am UTC](https://forum.babylonjs.com/t/how-to-assign-gravity-of-particles-based-on-mesh-emitter-position-vector-not-world/53584/3 "2024-09-20T11:25:37Z")

</div>

Hello 🙂

> [@TooCalm](#):
>
> i enabled gravity for those particles and it works perfect except of a problem. it’s usable only for static objects like bonfire where we always know that direction of particles will be up.

I think you might be confusing particle speed and particle acceleration.

- Gravity param exists because if you want particles to accelerate, most likely it will be due to gravity, which is always one direction (For example, hot smoke out of a fire, regardless of if the fire emitter moves, or not)
- Another param that you are not using here is particle emit direction. (See line 41 on this [Playground](https://playground.babylonjs.com/?BabylonToolkit#08YT34#89)) which can be in any direction rotate with a mesh, etc… For example that’s what I used for this rocket in a game I made a few years ago :  
 ![Screencast from 20-09-2024 13:23:34](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/e/cee08064f0c4ed1038b2985c7d38fcc1dfd42f77.gif)  
Is this what you are looking for ?

++  
Tricotou

---

<div class="post-metadata">

**Author:** ![TooCalm](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/toocalm/32/3301_2.png) [@TooCalm](https://forum.babylonjs.com/u/TooCalm)\
**Post date:** [September 20, 2024, 2:58pm UTC](https://forum.babylonjs.com/t/how-to-assign-gravity-of-particles-based-on-mesh-emitter-position-vector-not-world/53584/4 "2024-09-20T14:58:54Z")

</div>

Thanks for the answer  
Actually i tried to use those direction1, direction2 parameters but they did nothing and i found that it’s because i used sphere emitter. also direction1 and direction2 have such docs which are confusing too :  
Random direction of each particle after it has been emitted, between direction1 and direction2 vectors. **This only works when particleEmitterTyps is a BoxParticleEmitter**  
“[Babylon.js docs](https://doc.babylonjs.com/typedoc/classes/BABYLON.ParticleSystem#direction1)”

so i found that i can create **directed** sphere emitter and after that direction1 and direction2 started to work  
particleSystem.createDirectedSphereEmitter(1, new BABYLON.Vector3(-1, 8, -1), new BABYLON.Vector3(1, 8, 1));  
Thanks for help
