Constraint Particle System to only x&y axis?
Asked Answered
K

4

0

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.

Kermes answered 13/10, 2023 at 19:38 Comment(0)
T
0

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.

Theophilus answered 6/6, 2023 at 1:39 Comment(2)

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.

Kermes

Yes, I fear that is the only solution.

Theophilus
C
0

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:

I set the custom simulationspace to the transform that is moving vertically and now the particlesystems are not affected by the vertical movement.

Cleveite answered 23/2, 2017 at 14:6 Comment(0)
B
0

Some solutions: @Kermes

  • 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 :slight_smile:
Blameless answered 6/6, 2023 at 2:23 Comment(1)

This worked.

Carducci
L
0

If anyone still needs this, what worked for me was to enable the Limit Velocity over Lifetime parameter. In there I can enable the Separate Axes option and limit the desired axis velocity to 0 in World space.

image

I wanted to spawn particles in front and behind my character, so setting the volume scale to 0 on one axis wasn’t an option.

Leafy answered 9/8, 2023 at 15:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.