View Full Version : getting per particle rotation to stop after collision with floor?

01-28-2009, 11:12 AM
okay so I have a simple particle that emits and bounces onto the ground.
I've setup an extra attribute on the particle - vector PP called rotPP (clever huh)

in the creation expression I have:

particleShape5.rotPP = << rand (0,360), rand (0,360), rand (0,360)>>;

in the runtime BEFORE dynamics I have

particleShape5.rotPP = particleShape5.rotPP + rand (1,4);

now I want to setup a simple script that stops the rotation after colliding with the floor so I added a particle collision event. Then in my particleShape5 a added this expression into the runtime AFTER dynamics..

if (particleShape5.event >= 1)
particleShape5.rotPP = <<0,0,0>>;

prob is that every particle hits the ground then zero's its current rotation out. Is there any way for me to get the rotation that it has when it hits the ground?

01-28-2009, 11:58 AM
well, perhaps it would be easier only to increment your rotation if the collision hasn't occured yet ?? (an additional if statement in run before dynamics)
additional, when I work with my paticles rotation I tend not to randomize the amout of roatation added, because in most cases you want high speed rotation and low speed rotation of the particles - not particles randomly changing rotation speed (I hope it's understandable in English :D) - so normally I create an additional per particle variable like deltaRotation which is generated at creation, and then added every single frame (I also tend to use vectors and sphrand rather then scalars and rand) - in that case you could simply zero the deltaRotation value at collision moment

01-28-2009, 12:36 PM
wow thanks globus - thats a good basic explanation - the bit you mention about adding the IF statement in the runtime before dynamics bit is kinda useful.

I use the rand function in my vector PP attribute to generate a random xyz rotation value at creation - then I'm simply adding to it in runtime. I like this because each particle is born with a different rotation value.
the rand function in the runtime that I have gives a rotation value that varies the speed of each particle so some particles spin very slowly - others spin fast. theres no variation in the rotation speed with each particle.

the 2nd bit about delta rotation is interesting - do you have a mel example that I could possibly see please? I know I'm asking you to kinda solve my query there and I can kinda see what you are explaining but I dont really know the way about writing it down :/

01-28-2009, 01:17 PM
if you use rand at runtime you will get particles with rotation speed varying from frame to frame which is not always what you want, the difference is:
A)your rand version:
particle is born with rotation (10,20,30) (for example)
frame1: rotation + random rotation -> (10,20,30) + (1,1,1) - which is "slow version"
frame2: rotation + + random rotation-> (11,21,31) + (4,4,4) - which is fast
frame3: (15,25,35) + (2,2,2) -> medium version
f4: fast
f5: slow
and so on and so on
so particle accelerates differently from frame to frame and always goes in the same rotation direction (because of one rand - which gives scalar not vector) only at different speeds beacues it's always positive X positive Y and positive Z rotation, although the starting rotation is random, you get a similar rotation in the end

B) my typical random rotation setup:
additional per particle vector : deltaRotPP
create it's random value at creation: deltaRotPP=sphrand(4); (gives a random vector from <<-4,-4,-4>> to <<4,4,4>> each coordinate separately)
in runtime: rotPP+=deltaRotPP (incrementing our rotation)
in runtime: if collision occurred deltaRotPP=0;

in B) case we get a stable rotation speed in a random (but stable) direction, because each particle is rotated at a constant speed (because direction and rotation increment value is generated at birth by our sphrand expression)

I usually get my deltaRotPP sphrand values controlled by additional parameter so it's easy to change my rotation speed from gui not from script editor

i hope that helped

01-28-2009, 02:15 PM
groblus thats a great explanation of both methods - thankyou so much!!!

I'm gonna go and try to get that 2nd method working that you explained there :bounce:

01-28-2009, 03:06 PM
just tried that sphrand method you put up groblus - WOW! that works a treat - I've got some real nice random rotation and when they collide with the ground the rotation stops at the current xyz rotation it had when it collided!!

thanks once again for this great explanation :applause:

okay so I have another query - if I wanted a similar kind of effect on a particle sprite - what would I use - can I use sphrand again?

CGTalk Moderation
01-28-2009, 03:06 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.