Skip to content

Instantly share code, notes, and snippets.

@onionmk2
Created July 17, 2017 02:20
Show Gist options
  • Select an option

  • Save onionmk2/37fe3f65d1e26a600a307f5216273558 to your computer and use it in GitHub Desktop.

Select an option

Save onionmk2/37fe3f65d1e26a600a307f5216273558 to your computer and use it in GitHub Desktop.
change individual particles's velocity via script
using UnityEngine;
public class Trail : MonoBehaviour {
ParticleSystem system;
public Transform anchor;
private Vector3 anchorPosition;
private void Awake()
{
system = GetComponent<ParticleSystem>();
}
private void Update()
{
anchorPosition = anchor.transform.position;
var particles = new ParticleSystem.Particle[system.particleCount];
int particleCount = system.GetParticles(particles);
for (int i = 0; i < particleCount; i++)
{
var centerToThis = particles[i].position - anchorPosition;
particles[i].velocity = centerToThis.normalized * 100;
}
system.SetParticles(particles, particleCount);
}
}
@onionmk2
Copy link
Author

ParticleSystem.MainModule.simulationSpace must be World.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment