PDA

View Full Version : Evaluating Speed on objects


Moonz
11-28-2002, 08:05 AM
Anyone know how to write a melscript that kan determine the speed af an object?

what i want is the rate of a emitter to change depending the speed of the object its attached to

lets say a sphere for example..when its not moving, it wont emit particles, but when it starts moving i want a trail of particles that is EVEN, not like a bunch of particles when its standing still and then when it moves it gets up to higer speeds the particles become more apart from eachother..that is not what i want, That i can do with a simple dynamics simulation..=)

would be really great if someone can shed som light over this..dont even have to involve the rate of the particles in the beginning..just how to evaluate the speed of the object

Thanks

artifish
11-28-2002, 09:16 AM
get the world position wPP of your object in the previous frame and the world position WPC of your object in the current frame.
mag(wPC-wPP) is the current speed. you might add a scaling factor to control the emitter rate of your particles.

cheers, carsten

Moonz
11-28-2002, 09:24 AM
thanks man..will look into it...but since i know nothing about scripting i dont even know where to start..=)

artifish
11-28-2002, 09:43 AM
start with the docs :)

Moonz
11-28-2002, 10:52 AM
hehe..u think?..;)

fredrik
11-28-2002, 01:34 PM
This expression worked for me...

"Test" is the name of the emitter

float $position[3] = `xform -worldSpace -query -translation Test`;
vector $speed = `mag <<$position[0],$position[1],$position[2]>>`;
Test.rate = $speed*1000;



Fredrik Swerin

www.s-a.nu

alexx
11-28-2002, 06:25 PM
Originally posted by fredrik
vector $speed = `mag <<$position[0],$position[1],$position[2]>>`;


i guess $speed should better be declared as a float :)

and:
and i dont really think (without testing it), that this script really does what is expected. since it only calculates the distance from the object from the origin you will have emission even when the emitter is static; at least when it is at some position that is not the origin.
to get it right you will have to take the position from the current frame and calculate the distance to the last frame and get the magnitude of that result. that will do the job. (as artifish already mentioned.. listen to him. he knows what he is talking about :beer: )

cheers

alexx

alexx
11-28-2002, 06:39 PM
emm..
i think i can remember darklysomething that might make it easier for you:

create an object (simple)
make it a passive ridgid body
group it under the emitter

as far as i can remember the rigid body has attributes that tell you its velocity without doing this frame before/after math/mel stuff..
you can directly use that one..

hope i am right. cant check it right now.

cheers

alexx

CGTalk Moderation
01-13-2006, 10:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.