The title says it all. I’m working in a 2D game and the particle emitter shape is a Cone, Sphere, Hemisphere etc. There’s a way to shape the emitter to a circle or a quad? So particles are only generated in a 2-Dimensional world.
Update 1
This script sets the z-velocity of each particle to 0, successfully keeping the particles in the x-y plane. The only drawback I see is that this can cause some serious performance problems.
using UnityEngine;
using System.Collections;
public class ExplosionController : MonoBehaviour {
public ParticleSystem particleSystem;
void Update()
{
ParticleSystem.Particle[] particleArray = new ParticleSystem.Particle[particleSystem.maxParticles];
int particles = particleSystem.GetParticles(particleArray);
for (int i = 0; i < particles; i++)
{
Vector3 vel = particleArray[i].velocity;
vel.z = 0;
particleArray[i].velocity = vel;
}
particleSystem.SetParticles(particleArray, particles);
}
}
Update 2
As I only need to set the particles z-velocity to 0 only one time, because the explosion is a non-looping particle system, it’s easy to disable the loop option from the inspector and trigger the emission from the script itself:
using UnityEngine;
using System.Collections;
public class ExplosionController : MonoBehaviour {
public ParticleSystem particleSystem;
void Awake()
{
particleSystem = gameObject.GetComponent<ParticleSystem>();
}
void Start()
{
particleSystem.Emit(particleSystem.maxParticles);
ParticleSystem.Particle[] particleArray = new ParticleSystem.Particle[particleSystem.maxParticles];
int particles = particleSystem.GetParticles(particleArray);
for (int i = 0; i < particles; i++)
{
Vector3 vel = particleArray[i].velocity;
vel.z = 0;
particleArray[i].velocity = vel;
}
particleSystem.SetParticles(particleArray, particles);
}
}
It is also easy to adapt this script to your own needs, creating functions to alter color and whatnot.
Best regards.
Yeah, I've been searching about generating particles only in the x-y plane and found nothing. Currently I'm trying to do it through a script. I'll update the post if I get it working.
– KermesYes, I fear that is the only solution.
– Theophilus