View Full Version : random offset/movement?


jenny077
09 September 2007, 02:55 PM
hi guys,

I have a 1 poly plane and need to offset it or move it randomly within a range, say rand (-2, 2)
what is the simplest code for this?

jen

Segmoria
09 September 2007, 03:25 PM
Select your object and run the following:

string $selObj[] = `ls -sl`;
setAttr ($selObj[0]+ ".translateX") `rand -2 2`;
setAttr ($selObj[0]+ ".translateY") `rand -2 2`;
setAttr ($selObj[0]+ ".translateZ") `rand -2 2`;

trancor
09 September 2007, 05:47 PM
To add, for a multi object random move -

string $selected[]=`ls -sl`;
for($x=0; $x<size($selected); ++$x){
$randX=rand(-2,2);
$randY=rand(-2,2);
$randZ=rand(-2,2);
move -r $randX $randY $randZ $selected[$x];
}


I just used the move command rather than setAttr for a relative move. Denoted by the -r (relative) flag on the move command.

jenny077
09 September 2007, 02:03 AM
you guys are great.

thnaks a million!

jen

CGTalk Moderation
09 September 2007, 02:03 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.


1