Can you change the Velocity Over Lifetime of a Particle System using a Script?

Can you change the Velocity Over Lifetime of a Particle System using a Script?

If so, then how?

If not, then is there a way of changing a velocity of the Particle System when I press a button? The object that the Particle System is attached to is not moving and always stays at 0,0,0.

This is my current script that makes the Particle stop when I press the Up button. But instead of stopping, I want it to change its velocity, or make it swing.

	void Update () {
	
		if(Input.GetKeyDown(KeyCode.UpArrow))
		{
			particleSystem.Stop();
		}
	}

The documentation of Unity about the Particle System doesn’t have any code for changing its Velocity Over Lifetime.

So does it not exist or is it only not written there?

Thanks!

I’m on unity 5.3 and it is much more straightforward:

// Get the Velocity over lifetime modult
ParticleSystem.VelocityOverLifetimeModule snowVelocity = GameObject.Find ("Snow").GetComponent<ParticleSystem> ().velocityOverLifetime;

//And to modify the value
ParticleSystem.MinMaxCurve rate = new ParticleSystem.MinMaxCurve();
rate.constantMax = 10.0f; // or whatever value you want
snowVelocity.x = rate;

You can get access to an array of particles in a current system using:

ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleSystem.particleCount];
int count = particleSystem.GetParticles(particles);

Then you can iterate over the array and set the particles after. The reference page for particle can be found [here][1].

for(int i = 0; i < count; i++)
{
    float yVel = (particles<em>.lifetime / particles_.startLifetime) * distance;_</em>

particles*.velocity = new Vector3(0, yVel, 0);*
}

particleSystem.SetParticles(particles, count);
Place it all in a late update and that should work.
float distance = 3;
* void LateUpdate ()*
{
* ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleSystem.particleCount];*
int count = particleSystem.GetParticles(particles);
for(int i = 0; i < count; i++)
{
float yVel = (particles.lifetime / particles_.startLifetime) * distance;
particles*.velocity = new Vector3(0, yVel, 0);*
}_

particleSystem.SetParticles(particles, count);
* }*
This is my first post so apologies for any formatting mistakes.
_*[1]: http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem.Particle.html*_

it’s even more straight forward in Unity 2017.1.1f1

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    [SerializeField]
    private float speed;
    [SerializeField]
    private ParticleSystem particle;

    private ParticleSystem.VelocityOverLifetimeModule velocityModule;

    void Start()
    {
            velocityModule = particle.velocityOverLifetime;
    }

    void Update()
    {
            velocityModule.zMultiplier = speed;
    }
}