- Home /
Locking particle axis?
Is it possible to lock the axis of a particle? I'm creating a 2D game with 3D graphics and all of my objects z axis are locked however when a particle bounces off an object it's Z depth often changes ruining the whole effect.
Thanks in advance!
Answer by parveenkhtkr · Mar 14, 2014 at 11:19 PM
I am late to the party but this might be helpful to many out there. Use cone shape and set angel to 90 of cone. Thats it!
Answer by BoredKoi · Sep 03, 2010 at 03:25 PM
Have you considered a 2D plane / sprite animation instead of a particle system? There are many middleware solutions (some free) that will get you up and running quickly with potential processing benefits.
With the tools at hand in Unity (and without knowing what effect your are trying to achieve) here are a few ideas:
Ellipsoid Emitter:
- make sure you don't have any crazy tangential / world velocity going
- zero the Z property of the Ellipsoid itself on the Emitter component
Mesh Emitter:
- Emits particles from verticies; may work alright if you are billboarding your mesh
The Big Hammer:
- In LateUpdate, grab the .particles[] and slam their .position(s) wherever you want. Note the copy / reassign required to do this
http://unity3d.com/support/documentation/ScriptReference/ParticleEmitter-particles.html
Answer by skovacs1 · Sep 03, 2010 at 03:31 PM
I recommend going with BoredKoi's recommendation of sprite animations which can be much more performant than particle systems. As for the rest, since you are concerned about the movement after collision, it's not really about how you emit the particles. As BoreKoi stated, you could go through and set positions, but I think it may be easier to just set their "z" velocity to zero in stead.
for(var particle : Particle in particleEmitter.particles)
particle.velocity.z = 0;
Your z axis is going to be dependent upon your setup and if you're trying to lock on a setup-relative axis, you will need to transform the velocity into setup-local space and then back again. You can do this with Transform.InverseTransformDirection and Transform.TransformDirection. I believe that velocity is given in world coordinates, but if not, you may have to do twice as many conversions.
//Camera transform relative
var relativeVelocity : Vector3;
relativeVelocity = maincamera.transform.InverseTransformDirection(particle.velocity);
relativeVelocity.z = 0;
particle.velocity = maincamera.transform.TransformDirection(relativeVelocity);
When you set this velocity is also important. You could do it every frame in LateUpdate or at a set amount of time in FixedUpdate, but that's all rather inefficient or you could just do this in OnParticleCollision if its only a problem for collisions.
function OnParticleCollision(other : GameObject) {
for(var particle : Particle in particleEmitter.particles)
particle.velocity.z = 0;
}
or if you need to do this relative to an arbitrary transform
function OnParticleCollision(other : GameObject) {
for(var particle : Particle in particleEmitter.particles) {
var relative : Vector3;
relative = maincamera.transform.InverseTransformDirection(particle.velocity);
relative.z = 0;
particle.velocity = maincamera.transform.TransformDirection(relative);
}
Your answer
Follow this Question
Related Questions
Trigger particles when collide 0 Answers
Machine Gun Different Hit Particles 0 Answers
Ball bounce problem 1 Answer
Bouncing on collision 0 Answers
Bouce after collision 1 Answer