# instances rotation alignment to the ground

 05 May 2012 fxjungle New Member portfolio andres abr town, US instances rotation alignment to the ground Hi, I have faced this problem very often and always found a cheap trick to get the shot done. But I refuse to not know how to do it the fancy way, so here it goes. Say you have a particle system with instanced geo that has a random rotation but when it collides with the ground plane you want it to align so it lays flat on the ground, so you need to have it rotate from the rotated position at collisionTime into that last position that will have it align to the surface it collided with. So, I have all the system set up, I am stuck at that last part. Though I have used several options I am stuck at using angleBetween just because I am fairly certain this is the way to go. Anyone out there that can either help me out or just point me in the direction? Thanks, share quote
 05 May 2012 pramod2136 New Member portfolio pramod gurugari VFX MAKUTAVFX Vijayawada, India Did you use expression for the rotation If not you this expression for the particles Custom rotaction. Vector Custom rotation = <>; Now type in runtime dyn Custom rotation += 1; create other rand rotation in array with float per particle (add intial state attr) (In creation) Rand rotation = rand(-1,1); Runtime Custom rotation += rand rotation ; Speed float Speed = mag(velocity)/30; Custom rotation += rand rotation *speed; share quote
 05 May 2012 Aikiman Some guy   portfolio Jeremy Raven Wellington, New Zealand Well I remember doing this before but forgot how I did it and just spent a good 2-3 hours trying to figure it out and Im sure it wasn't this hard but I did find a solution, wow Im rusty. I tried doing it with the angleBetween but that requires 2 axis and returns an angle in degrees, the problem is what happens if you have random rotations to start with? I tried unitizing the rotations but the angleBetween command doesnt seem to like anything but whole numbers for axis. It would be good to see this work though. I suck at math. However I have found a workaround and that is using the hermite function instead. Have a look at it - myRotPP = hermite ( origRot, finalRot, <<0,0,0>>, <<0,0,0>>, linstep(0,highestY,particleYposition)); This rotates your particle from its original random position to your desired angle over the distance it has to fall to ground zero. __________________ Vimeo share quote
 05 May 2012 jungleFX New Member portfolio Andres Berkstein FX Artist Marina del Rey, USA Originally Posted by Aikiman: Well I remember doing this before but forgot how I did it and just spent a good 2-3 hours trying to figure it out and Im sure it wasn't this hard but I did find a solution, wow Im rusty. I tried doing it with the angleBetween but that requires 2 axis and returns an angle in degrees, the problem is what happens if you have random rotations to start with? I tried unitizing the rotations but the angleBetween command doesnt seem to like anything but whole numbers for axis. It would be good to see this work though. I suck at math. However I have found a workaround and that is using the hermite function instead. Have a look at it - myRotPP = hermite ( origRot, finalRot, <<0,0,0>>, <<0,0,0>>, linstep(0,highestY,particleYposition)); This rotates your particle from its original random position to your desired angle over the distance it has to fall to ground zero. Thanks Aikiman, I am out of the office and my scene files are there, will post one with my almost descent result using angleBetween. I tried the hermite and I get some funky results. I am using the birthPos as the highestY pos. One of the problems is that it automatically snaps on the second frame and the instances just fall flat. I tried using a locators position or even the collisionTime event to trigger the Hermite but still not getting the result. Most of the time they don't even lay flat on the ground (I am using a cylinder as an instance) I know it should be easy, but for some reason I am just failing :( Well, will keep posted when and if I have time to resolve this. pramod2136, I think what you are trying to give me is just a rotation expression, and in that case I would definetly add a axis with at least 3 different rand floats and use this attr to rotate in x or y or z, and not all at the same time, since that rotation gets funky looking, kinda like a gimbal lock. Thanks! __________________ www.berkstein.com share quote
05 May 2012
nParticles have the "rotation" parameter that can be used to drive instances.

This is much better than trying to hack rotations from start to 0 as the rotations are more natural. So here is an example and script that accomplishes the "snap to 0" using the angular velocity property to trigger the final behavior (note that this works perfectly even if particles are knocked around gain after coming to a stop)

//define a threshold value for magnitude of angular velocity
\$t = 3;

//trigger evaluation on threshold angular velocity while ignoring any still particles
if (mag(nParticleShape1.angularVelocityPP) < \$t && angularVelocityPP != <<0,0,0>>){

//use a custom attribute to initialize start rotation only if its 0
if (nParticleShape1.frotPP == <<0,0,0>>){ nParticleShape1.frotPP = nParticleShape1.rotationPP;}

\$frot = nParticleShape1.frotPP;
\$av = mag(nParticleShape1.angularVelocityPP);

\$l = \$av/\$t;

//using linsteps we define a vector that starts with start rotation and ends up as 0
nParticleShape1.rotationPP = <<linstep(\$frot.x,0,\$l),linstep(\$frot.y,0,\$l),linste p(\$frot.z,0,\$l)>>;
}
Attached Files
 stooch_particleRollto0.zip (9.7 KB, 92 views)
__________________
From Russia, with love @ stooch.tv

Last edited by stooch : 05 May 2012 at 07:57 PM.

 05 May 2012 jungleFX New Member portfolio Andres Berkstein FX Artist Marina del Rey, USA Originally Posted by stooch: nParticles have the "rotation" parameter that can be used to drive instances. so you dont have to do any fancy scripting anymore. just set your instancer to use this parameter and you are done. (make sure you enable calculate rotation in the nParticleShape) Thanks, I know this, but I am about to build a rig to be used in maya 2009, some times the new and fancy tools are not available __________________ www.berkstein.com share quote
 05 May 2012 Aikiman Some guy   portfolio Jeremy Raven Wellington, New Zealand Nice one Stooch, very cool. Mine doesnt handle bouncing but it could be adjusted to work with mag(velocity) instead rather than distance. __________________ Vimeo share quote
 05 May 2012 jungleFX New Member portfolio Andres Berkstein FX Artist Marina del Rey, USA Thanks guys! both examples are really helpful. I completely forgot about the angularVelPP attr. And I now see I went completely another direction which would probably never have gotten me where I needed to get to. stooch, that was what exactly was I looking for. __________________ www.berkstein.com share quote
 05 May 2012 Aikiman Some guy   portfolio Jeremy Raven Wellington, New Zealand Yeah I am pretty confused but I think I have it sussed now. The rotationPP works in degrees whereas the angleBEtween requires 2 vectors based on unit axis but it produces an angle in degrees. AimUpDir and AimDirection for example all work in unit axis also which is why you can rotate an instance using sin and cosine. The prob I still have is that using linstep to rotate the object appears to be ideal for aimUpDir because it goes from 0 -1 but I am still getting a snapping effect rather than the nice interpolation we can get with sin and cosine, that bit doesnt make sense. Stooch's use of rotationPP resolves all that confusion. __________________ Vimeo share quote
 05 May 2012 Schempp Know-it-All portfolio Eric Schempp Stockholm, Sweden Let me highjack this thread for just a minute =) Does those setups with the expressions from you Aiki and stooch work if the ground or object that the particles collide with is an uneven geo? will the particles have the correct rotation when they have stopped? __________________ Voxels for dinner. _____________ http://esvfx.wordpress.com/ maya vfx blog share quote
 05 May 2012 Aikiman Some guy   portfolio Jeremy Raven Wellington, New Zealand Mine wont Stoochs will. Mine is based on Y axis and zero. Stoochs is based on angularVelocityPP. __________________ Vimeo share quote
 05 May 2012 Schempp Know-it-All portfolio Eric Schempp Stockholm, Sweden Ok, cool! thanks guys! This might come in handy! copy and save =) __________________ Voxels for dinner. _____________ http://esvfx.wordpress.com/ maya vfx blog share quote
 05 May 2012 stooch Lord of the posts   portfolio Dimitri Loginowski VFX Artist + Designer Handsome, LLC Beverly Hills, USA actually my final vector is hard coded to end to <<0,0,0>> so if the ground is uneven, then this wont really respect the normals, it would be fairly trivial to setup normal orientation though, if anyone wants it i can look into it when i get home. __________________ From Russia, with love @ stooch.tv share quote
 02 February 2013 HowardM Digital Ho   ---------------------> FX TD a large dark room . . . . ... . .. ...with bright monitors United Kingdom Hey Stooch, Any chance you can show us how to make them land correctly on an uneven surfaces? And is it possible to make the pieces slowly rotate flat, rather than snap to position? I imagine that is a major pain in the arse! Cheers! __________________ . Reel - 3DInk.com Filmography -IMDB R&D - VIMEO *please read- cyanbsl.blogspot.com/* Last edited by HowardM : 02 February 2013 at 12:55 PM. share quote
 02 February 2013 HowardM Digital Ho   ---------------------> FX TD a large dark room . . . . ... . .. ...with bright monitors United Kingdom In regards to the snap, is this because you haven't declared ParticleShape1.frotPP? And what was \$r for? Or am I missing something? __________________ . Reel - 3DInk.com Filmography -IMDB R&D - VIMEO *please read- cyanbsl.blogspot.com/* Last edited by HowardM : 02 February 2013 at 05:12 PM. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.