# Locking particle axis?

 0 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! more ▼ asked Sep 03 '10 at 10:41 AM ROM 277 ● 46 ● 49 ● 58 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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 more ▼ answered Sep 03 '10 at 03:25 PM BoredKoi 391 ● 7 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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); } `````` more ▼ answered Sep 03 '10 at 03:31 PM skovacs1 10k ● 11 ● 25 ● 92 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2584
x335
x206
x129
x121

asked: Sep 03 '10 at 10:41 AM

Seen: 1437 times

Last Updated: Sep 03 '10 at 10:41 AM