Search Unity

Particle systems and gravity

Discussion in 'Physics' started by unity_2e_7kz8DqNKDjA, Feb 12, 2018.

  1. unity_2e_7kz8DqNKDjA

    unity_2e_7kz8DqNKDjA

    Joined:
    Jan 31, 2018
    Posts:
    9
    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?
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    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.

    https://docs.unity3d.com/ScriptReference/ParticleSystem.ForceOverLifetimeModule.html

    And a link to how to set the X axis only, with an example: https://docs.unity3d.com/ScriptReference/ParticleSystem.ForceOverLifetimeModule-xMultiplier.html

    Just set up the x, y and z axes, with the vector you want, by modifying that example script.
     
    panhj2, Levr01, Taumatropo and 5 others like this.
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Update: In 2018.3, you can add a spherical Particle System Force Field Component to achieve spherical gravity! (CC @AcademyOfFetishes )
     
    laurentlavigne and burnout156 like this.
  4. ReadyPlayGames

    ReadyPlayGames

    Joined:
    Jan 24, 2015
    Posts:
    49
    I played around with the Force Field Component for far longer than I should have. It's really cool.
     
    richardkettlewell likes this.
  5. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    305
    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.
     
    Soaphog likes this.
  6. amitDklein

    amitDklein

    Joined:
    Apr 10, 2017
    Posts:
    20
    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

     
    richardkettlewell likes this.
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
  8. OldAntelopes

    OldAntelopes

    Joined:
    May 3, 2022
    Posts:
    2
    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?)
     
    Last edited: May 20, 2022
  9. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    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 ;-)
     
  10. OldAntelopes

    OldAntelopes

    Joined:
    May 3, 2022
    Posts:
    2
    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 :)
     
  11. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    OldAntelopes likes this.