- Home /
Constraint Particle System to only x&y axis?
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.
Answer by jofa · Aug 21, 2018 at 02:49 PM
Some solutions: @DanielRS
Don't use XY constrain, because particle effect looks much better with 3D shape. Just move Camera back on Z axe and adjust Far clipping plane to have enough space for particles to render
If you really need that, you can set particle.shape.scale.Z to zero (or in new Unity use shape Circle :)
Answer by giano574 · Feb 27, 2014 at 09:06 PM
In the "renderer" of the particle system you can chose the render mode "horizontal billboard". If you are talking about only creating the particles in the x-y plane, I don't know if that is possible. Probably not.
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.
Answer by eits · Feb 23, 2017 at 02:06 PM
I had a similar problem when my game was moving vertically and the character horizontally. I wanted the particlesystem to be affected only by the horizontal movement. For this I noticed there is the option to set custom simulationspace:
https://docs.unity3d.com/ScriptReference/ParticleSystemSimulationSpace.html
I set the custom simulationspace to the transform that is moving vertically and now the particlesystems are not affected by the vertical movement.