PDA

View Full Version : Sprites direction


Bernard397
07-10-2008, 09:23 PM
Hello,


I've got a particle system with sprites setup. I've mapped a image of an arrow to the sprites.
Now I want the arrows to face the direction the particles are moving....
Is this possible?



thanks,


bern

Aikiman
07-10-2008, 10:08 PM
yep it is but it may take me 1 or 2 goes to get it right but heres the gist of it.

First you need to get the angle between velocity and the world up vector (Y) then convert that angle to degrees using rad_to_deg.

Then you apply that to the spriteTwistPP. However what you find is that it only works on the positive z (assuming you have you camera facing down the -x axis).

So you gotta create another variable that will blend between pos and neg z, thats where you use a smoothstep of 0.5 and -0.5 on the $vel.z. [Edit] Now you multiply the smoothstep by 2 then take away 1 to bring the values to -1, and 1.
Then multiply that to the result of rad_to_deg and apply it to spriteTwistPP.

Have a go and give me a yell if you get stuck, I may have missed something out so I gotta check to see if it works.

Aikiman
07-11-2008, 08:06 AM
if you just wanna do it with the push of a button then you need to copy and paste this into your particle expression editor.

float $angle = angle(particleShape1.velocity, <<0,1,0>>);
float $deg = rad_to_deg ($angle);
vector $vel = velocity;
float $blend = (smoothstep (-.5, .5, $vel.z)*2)-1;
particleShape1.spriteTwistPP = $deg*$blend;

CGTalk Moderation
07-11-2008, 08:06 AM
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.