- Home /
How do you make random local velocity for particles?
I'm pretty new to Unity and found I couldn't make the particle effect I was going for (using a particle emitter component) without random local velocity. My first thought was to make a script adding values which would translate to world values then be added to the existing rndVelocity options. I can't figure out how to do it though. This is what I tried:
var rndLocalVelX : float = 0; var rndLocalVelY : float = 0; var rndLocalVelZ : float = 0; var particlez : ParticleEmitter; var relativeDirection : Vector3;
function Start () { var randomAdd : Vector3; randomAdd = Vector3( rndLocalVelX, rndLocalVelY, rndLocalVelZ);
relativeDirection = transform.TransformDirection(randomAdd);
particlez = GetComponent(ParticleEmitter);
//adding a random value to local velocity:
particlez.rndVelocity += relativeDirection;
}
Answer by runevision · Feb 09, 2011 at 12:04 PM
I don't understand what you're trying to do, but anyway, the variable called Rnd Velocity
is already local random velocity. So you can just set that value directly.
Answer by Tobs 1 · Feb 09, 2011 at 12:42 PM
do you need to add positive and negative velocity? If so, use Random.Range(min, max)
randomAdd = Vector3(Random.Range(-rndLocalVelX, rndLocalVelX), Random.Range(-rndLocalVelY, rndLocalVelY), Random.Range(-rndLocalVelZ, rndLocalVelZ));
you would set this as Velocity instead of rndVelocity ofcourse