Search Unity

Disable gravity completely on particle system

Discussion in 'Scripting' started by mrCharli3, Sep 13, 2020.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    How can I disable gravity completely on a particle system? Either in inspector or via Script.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,743
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    You just set Gravity to 0, or don't turn on gravity in the first place.
     
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    You mean in the entire project? I need gravity for other things...

    Setting gravityModifier to 0 is not the solution. you would need to set it to -globalGravity to cancel out global gravity, I can do that but wanted to know if there was a simple boolean. I guess not.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,743
    Did you even try this or are you pre-complaining? This is one link in from the main module link I gave you above:

    https://docs.unity3d.com/ScriptReference/ParticleSystem.MainModule-gravityModifier.html

    This basically will turn off gravity effect on the one instance of a particle system that you do it on. Gravity multiplied by zero will have no effect for that system.

    Let me remind you that your original question said,

    "How can I disable gravity completely on a particle system? "

    If that is NOT what you want then please explain further because that's what all the responders above have given you.
     
  7. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    That doesn't make sense to me. The "gravity" you set in Project Settings -> Physics -> Gravity doesn't affect particle systems. They use their own, completely independent GravityModifier, on a per-particle-system basis. I'm not aware of any project-wide way to set the gravity of every particle system to a particular value, and in most cases, I can't see how I would ever want that behavior.

    So, if one of your particle systems appears to be affected by gravity, then I assume that means you've already set its Gravity Modifier to some non-zero value:

    upload_2020-9-13_18-3-33.png

    But as Kurt said, maybe try to rephrase the problem. It's not making sense to me.
     
  8. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    I have tested this a lot before posting this question, my particles are for sure effected by the global gravity, and setting the modifier to 0 does not help, only setting the modifier to -global gravity fixes the issue, I thought it was odd too.

    I cannot tell you how it's supposed to work, but I am 100% sure that this is what is happening in my case.
     
    Last edited: Sep 14, 2020
  9. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Pre-complaining...

    Yes I've tested all of this and I understand my question could be interpreted that way and that is my bad, no need to be so passive agressive. What I meant was if there is any way to make it so global gravity does not effect the particle system. Setting the modifier to 0 turns off any modification to the global gravity, it does not disable the gravity.
     
  10. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Ah, good point. You're right, I'm wrong. I forgot all about that. As the name suggests, "Gravity Modifier" is a modifier against the current Physics gravity.

    But then you said that settings Gravity Modifier to 0 doesn't help. Are you saying that the particles still fall due to gravity even if gravity modifier is set to 0? Because that's now what I'm seeing in a test. Are you sure you don't just have some velocity or noise or some other force acting on your particle system?

    In a brand new project, here's a default particle system with Gravity Modifier set to 0:

    upload_2020-9-14_9-55-27.png

    The particles are going up because of their initial velocity. Compare that to Gravity Modifier set to 1:

    upload_2020-9-14_9-55-53.png

    Or when set to -1, where they much more rapidly rise and leave the screen very quickly:

    upload_2020-9-14_9-56-27.png

    Anyway, at this point maybe you could show a short video of the behavior you're seeing. Specifically, show the "gravity" you're seeing even when Gravity Modifier is set to 0.
     
    PraetorBlue likes this.
  11. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,910
    Im guessing there's some velocity over lifetime or similar setting enabled that appears to be gravity but is not. Or perhaps the system is attached to a Rigidbody.
     
    Joe-Censored and Kurt-Dekker like this.
  12. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Thanks, I cannot say 100% if my velocity etc is interfering, that is possible!

    All I can say is that when I increase my global gravity from 9.81 to 50, my particles completely change behaviour (start falling much earlier). Which leads me to believe that the global gravity change is the reason for the change in behaviour (seems like a reasonable assumption).

    I have since solved this in another way, but still interesting to know I think. I still think a "disable global gravity" box on a particle system would be neat.

    In your example, if you keep your modifier at 1, but increase the global gravity (by a lot), you will probably see the result I am referring to. Other than that your examples make total sense and behaves just the way I would expect the modifier to, I have no issues with that.
     
  13. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,743
    I have set up a horizontal blast of particles, set the particle system gravity modifier to 0, and now it does not matter what my Physics (or Physics2D) gravity is set to: the particles stream to the right without falling.

    By setting the gravity modifier to 1 it is instantly and constantly modified by the latest Physics.gravity setting (not by Physics2D.gravity).

    I have to think you have something else going on. Make a fresh scene, make a fresh particle system, make it emit sideways, set gravity modifier to zero. Do the particles accelerate from gravity? Mine absolutely do not.
     
  14. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Odd, maybe that is it then. Ill give it a go and see If I get the same results :)