Emitting particles one by one ... 2003-12-12 - By John Cassella
Back Hey Gary,
use the positon of the center of your gun barrel geometry and the locator at the end of the gun barrel to derive the aim vector like this: (mind the word wrap)
//BEGIN MEL: float $posLoc[] = `xform -q -ws -t locator1`; float $posGun[] = `xform -q -ws -t gun`;
float $dir[] = {($posLoc[0] - $posGun[0]),($posLoc[1] - $posGun[1]),($posLoc[2] - $posGun[2])} ; vector $normalized = <<$dir[0], $dir[1], $dir[2]>>; $normalized = `unit $normalized`; //vector $velocityVector = $normalized; // this is your velocity vector !!!!
//now you can multiply the $velocityVector by a speed multuplier to make your bullets go faster or //slower or even add a little random speed by multiplying a small random (rand(.01,.1)) against //the velocity vector.
emit -object particle1 -position $posLoc[0] $posLoc[1] $posLoc[2] -attribute velocity -vectorValue ($normalized.x) ($normalized.y) ( $normalized.z) ;
// END MEL
you normally need to feed the emit command a set of 3 floats to represent a velocity vector I convert the $dir value to a vector so I can normalize it and then multiply a speed value to it easier. but you could also just multiply your speed value by each of the 3 float array members and use the normalize command on a set of 3 floats as well.
Hope this helps!
-john
garyc wrote: > Hi John, right, I setup the "emit" command in my expression and it works > just fine, I have taken the position data from a null that I have parented > to the gun barrel, so I have the particles starting off in the right place. > My only problem (well be it more a lack of knowledge) is how can I get a > vector (i.e. a direction) for the particle when the barrel is moving around. > Like I say I currently have a null parented to the barrel that gives me the > position but I have the particle vector set to <0,0,50> so my particles > always shoot off down "z" regardless of the guns orientation. Is there some > way I can generate a correct vector from the same null that gives me my > position, its "z" axis always (as its parented) points the right way, I just > need that as a vector to plug into the emit command. > > PS: sorry if this is a no brainer questin for the maths guys out there, I am > just trying to get my head around the maths thats goes with Maya ;) > > cheers gary. > > > >>Best bet is the "emit" command. set up an expression that gets the > > direction of the gun and > >>positon, for the velocity vector of the particle and muzzle position. >> >>then plug those numbers into the expression with the emit command to emit > > a particle > >>per frame. >> >>if you want more than one "shot" per frame (machine gun) >>you can offset the position of the "bullets" up and down the velocity > > vector with some > >>random value. and loop on the emit command > > > > -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- > List-help: <mailto:listar@(protected)?Subject=help> > List-unsubscribe: <http://www.highend3d.com/maya/listserver/> > List-subscribe: <http://www.highend3d.com/maya/listserver/> > List-archive: <http://www.highend3d.com/maya/archive/> > > >
-- John Cassella (aka redpaw) 3d Animator |""" \\ // |""" \ / | // \\ redpaw@(protected) direct line 323-308-3018
Where am I going, and how did I get in this handbasket!
Backward conditioning: Putting saliva in a dog's mouth in an attempt to make a bell ring.
...Last Night I lay in bed looking up at the stars in the sky and I thought to myself, "Where the heck is the ceiling?"
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- List-help: <mailto:listar@(protected)?Subject=help> List-unsubscribe: <http://www.highend3d.com/maya/listserver/> List-subscribe: <http://www.highend3d.com/maya/listserver/> List-archive: <http://www.highend3d.com/maya/archive/>
|
|