Particle systems and gravity

I’m writing a game that takes place on a spherical planet. Therefore, the gravity vector should be directed to the centre of the planet. I have 2 particle systems at different points on the planet. So whatever direction I might set Physics.gravity to, it will be wrong for one of them. Is it possible to give each particle system its own gravity direction?

It’s not possible using the physics gravity directly, but you could do it using the Force over Lifetime module.

If you can write a script, you could set the force direction and strength for each system.

And a link to how to set the X axis only, with an example: Unity - Scripting API: ParticleSystem.ForceOverLifetimeModule.xMultiplier

Just set up the x, y and z axes, with the vector you want, by modifying that example script.

8 Likes

Update: In 2018.3, you can add a spherical Particle System Force Field Component to achieve spherical gravity! (CC @AcademyOfFetishes )

2 Likes

I played around with the Force Field Component for far longer than I should have. It’s really cool.

1 Like

What if I just want to change the direction of gravity overall? I can’t seem to figure out how to do that with the Force Field Component. It always wants to pull towards the transform point.

1 Like

Unity 5.0: there’s a Gravity Modifier input that lets you determine the effect of world gravity on the particles
Just change it to 1 and you will have gravity

1 Like

Alternatively, the Direction settings in the Force Field Component will let you specify an arbitrary directional gravitational force:

Anyone know if the gravity in the ParticleSystemForceField is calculated ‘properly’ (as in its inversely proportional to the distance squared) or if its the same force applied irrespective of distance?
(I think it seems to be the latter which is … a pain (if you’re using particles to represent large-scale gravitational bodies :] ) ). Assuming that conclusion is correct, can anyone recommend an approach for changing particle force behaviour directly? e.g. Have a specific update function per particle?)

This sounds like a great use for our C# job system support. You can write a particle job, and compile it with Burst for great performance :wink:

Thanks for the pointer, Richard… I’m relatively new to the engine and haven’t got to the job system yet… Will have a dig, thx :slight_smile:

Good luck! There are some code examples in our early-feedback thread here: Particle System C# Job System support

The feature is finished and in the 2020 LTS, though, just to be clear. The early-feedback thread is old :slight_smile:

1 Like