So for my game I want to be able to create a particle emitter. The difference is that particles emitted only move up, down, left, right, forward, and backward. Similarly, I want the particles to change direction randomly, but at sharp 90-degree angles.
So I wouldn’t know where to begin. What do I need to do?
If you’re creating a smallish number of “base” particles, it might be easier to spawn a collection of GameObjects that you can move, each of which has a TrailRenderer or ParticleSystem attached.
If you really need that level of control, you could manually assign the velocity of each particle at regular intervals. Something like this:
Particle[] particles;
ParticleSystem emitter;
void Start() {
emitter = GetComponent<ParticleSystem>();
particles = new Particle[emitter.maxParticles]; //make sure maxParticles is NOT huge!
emitter.Play();
float randomizeSeconds = 1f;
InvokeRepeating("Randomize", randomizeSeconds, randomizeSeconds);
}
void Randomize() {
int count = emitter.GetParticles(particles);
for (int i=0; i<count; i++) {
float x = Random.Range(-1f, 1f); //maybe restrict to either -1 or 1, no range?
float y = Random.Range(-1f, 1f);
particles*.velocity = new Vector3(x, y, 0f);*