PDA

View Full Version : Instances to lay flat on collision?

 The Cobbler05-04-2010, 02:23 AMWell...here it goes. I have sifted through numerous threads..and boards. I have seen the leaf tutorial ( learning-maya ), but still can't seem to get the instances to actually land flat. In my head it all makes sense, but I haven't the slightest idea how to script it. I know at ground level I want my rotation to be <<0,0,0>> per particle. I know they start with a random rotation and in runtime they do a += << ?,?,?>> but at a certain point in their decent to the ground I need them to take that current rotation and make it go to zero by the time it hits the ground...I need to figure out how to get that to work in script language. Any ideas or anyone who can validate my theory or have a better way to achieve this? Any and all help would be much appreciated..thanks in advance. theCobbler
efecto
05-04-2010, 10:33 AM
you could stop the rotation based on the velocity?

float \$vel = mag(velocity);
if (\$vel < 0.1) { // stop rotation if velocity is lower than 0.1
rotPP = 0;
}

something like that. You could adjust the speed of rotation based on velocity so that rotation speed will decrease as velocity decreases as well.

The Cobbler
05-04-2010, 12:16 PM
Efecto,

Thanks for this you have simplified the lying flat and rotating into a few lines...it works and can be utilized in most cases.

My biggest issue I can't wrap my head around is how to get the instances gradually land flat. So the scenario would be an instanced plane...(confetti or something lets say )...bursts out of an emitter...it has fantastic motion and such.....but when it is about 5-10 units ( or whatever really ) above the ground it knows that it will need to rotate 2 more times either really slow or faster in order to lay flat on the ground. So really a minimum position ( ground ) and a maximum position ( locator that tells it where or the distance from ground) and a way to tell it to rotate back to <<0,0,0>> between those points ( by the time it hits the minimum position ).

I just can't figure it out in my head..does it even make sense? the concept?

Thanks for replying as well it is very helpful to get other peoples opinions and assistance.

Cheers,

theCobbler

The Cobbler
05-04-2010, 12:22 PM
Actually,

hahahaha.....too early.

Thanks again yeh!

The Cobbler
05-04-2010, 12:57 PM
Efecto,

So here is what I have.

float \$vel = mag(particleShape1.velocity);
float \$randO = rand(360);

particleShape1.rotPP += <<2,6,4>>;

if (\$vel < 2) {
particleShape1.rotPP = << 0,\$randO,0>>;
}

else

particleShape1.rotPP += <<2,6,4>>;

The only reason I have the \$ranO in there is because when they land they were all facing the same way..however the \$randO makes them spin on the ground in Y so it rotates every frame..is there a better way to have them land with varying rotation on Y...but not spin every frame?

Aikiman
05-04-2010, 08:37 PM
this gives you a gradual rotation to land flat although still quite primitive. userVector1PP is a custom attr that has a rand(360) in each component in creation expression and plugged into the rotation in the instancer.

// Runtime Expression

vector \$pos = particleShape1.position;
vector \$planePos = `xform -q -ws -t pPlane1`;
vector \$diff = \$pos-\$planePos;
vector \$Vel = userVector1PP;
vector \$userVol = <<(\$Vel.x * smoothstep(0,10,\$diff.y)), \$Vel.y, (\$Vel.z * smoothstep(0,10,\$diff.y))>>;
particleShape1.userVector1PP=<< \$userVol.x, \$userVol.y, \$userVol.z >>;

If you want the rotation to happen earlier then change the linstep value from zero to a higher value than 10. Basically im using the distance between the particle and the pPlane1 to drive rotations to zero in x and z. Not 100% convincing but workable.

EDIT For some reason these values work better for my smoothstep than above:
smoothstep(-30,30,\$diff.y)
Im not sure why but for some reason the rotation to zero was happening too quickly so I had to reduce the Y distance to a negative value to get the rotation to finish on collision point.

http://rapidshare.com/files/383598358/leaves.mp4.html

CGTalk Moderation
05-04-2010, 08:37 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.