Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Changing ParticleSystem attributes in script for future particles only

Discussion in 'General Graphics' started by caeonosphere, Aug 14, 2023.

  1. caeonosphere

    caeonosphere

    Joined:
    Jul 6, 2017
    Posts:
    4
    I'm trying to spawn particles with random angular velocity between 30 and 66, but in either direction. I could random between -66 and 66, but then of course I'd end up with some particles barely rotating at all. Instead I randomize between 30 and 66, and put this in Update:

    Code (CSharp):
    1. if (Random.value < .5) {
    2.     var rol = particles.rotationOverLifetime;
    3.     rol.z = new ParticleSystem.MinMaxCurve(-rol.z.constantMax, -rol.z.constantMin);
    4. };
    Works great, except this also changes the angular velocity of particles that have already been spawned, resulting in them jittering back and forth. Is there a way to "detach" spawned particles from the ParticleSystem's values so they only affect future particles?

    I'd also happily hear about a smarter way to get this effect.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,248
    try particles.main.startRotation instead.
     
  3. caeonosphere

    caeonosphere

    Joined:
    Jul 6, 2017
    Posts:
    4
  4. caeonosphere

    caeonosphere

    Joined:
    Jul 6, 2017
    Posts:
    4
    Aha! I think I understand: if I give half of my particles an initial 180 degree rotation about the X, their angular velocity will take them in the opposite direction. Works great, thanks.
     
    richardkettlewell likes this.