Created
July 17, 2017 02:20
-
-
Save onionmk2/37fe3f65d1e26a600a307f5216273558 to your computer and use it in GitHub Desktop.
change individual particles's velocity via script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ParticleSystem.MainModule.simulationSpace must be
World.