PDA

View Full Version : Align an object to an animated object


mandel
11-21-2005, 01:07 AM
I'm tryin to write a script that will let me select an object and align it to another objects position on every frame of an animation. For instance i have an animated object, and i need a new object to follow its transfroms exactly, but i can't link it, because it needs to be linked to another object in the rig for the game engine. So I think i would make a loop statement that looped through an objects keyframes and aligned it at each frame, but I'm having a little trouble. Thanks in advance for any help.
- David

Bobo
11-21-2005, 04:26 AM
I'm tryin to write a script that will let me select an object and align it to another objects position on every frame of an animation. For instance i have an animated object, and i need a new object to follow its transfroms exactly, but i can't link it, because it needs to be linked to another object in the rig for the game engine. So I think i would make a loop statement that looped through an objects keyframes and aligned it at each frame, but I'm having a little trouble. Thanks in advance for any help.
- David



theAnimSource = $Teapot01
theObjToAlign = $Box01
for t = animationrange.start to animationrange.end by 1 do
with animate on at time t theObjToAlign.transform = theAnimSource.transform



This will keyframe the positio,rotation and scale of Box01 to the animation of Teapot01 on every frame... Change 'by 1' to 'by 5' and you will get a keyframe on every 5th frame...

j-man
11-21-2005, 11:32 AM
Can you use a script controller on the objects transform? something like:


dependson $teapot01
$teapot01.transform


or maybe wire parameters.

J.

mandel
11-21-2005, 02:49 PM
Thanks a lot, works perfectly :)!
I've wrote a lot of simple scripts, but I'm still having trouble grasping the loop statements.
I'm tryin to get better with max script, maybe you guys can help me understand the script. This is what I get out of whats happening.

theAnimSource = $Teapot01
// this defines the variable $teapot as theAnimSource
theObjToAlign = $Box01
// this defines the variable $box01 as theObjToAlign
for t = animationrange.start
// this opens a for loop statement and defines t as the
// animationrange.start to animationrange.end
by 1 do with animate on
// by 1, says to do it by 1 incriments, with animate on
// tells max to turn animate on
at time t theObjToAlign.transform = theAnimSource.transform
// at time t says to use the time defined by variable t
theObjToAlign.transform = theAnimsouce.transform
// this is the function that aligns the transforms, of the variables
// assigned earlier, it repeats the function as per the loop defined
// above

Thanks for the script!!
Cheers,
David

PEN
11-21-2005, 03:20 PM
How about just using constraints? Would this not be easier?

Bobo
11-21-2005, 11:01 PM
Thanks a lot, works perfectly :)!
I've wrote a lot of simple scripts, but I'm still having trouble grasping the loop statements.
I'm tryin to get better with max script, maybe you guys can help me understand the script. This is what I get out of whats happening.

theAnimSource = $Teapot01
// this defines the variable $teapot as theAnimSource
theObjToAlign = $Box01
// this defines the variable $box01 as theObjToAlign
for t = animationrange.start
// this opens a for loop statement and defines t as the
// animationrange.start to animationrange.end
by 1 do with animate on
// by 1, says to do it by 1 incriments, with animate on
// tells max to turn animate on
at time t theObjToAlign.transform = theAnimSource.transform
// at time t says to use the time defined by variable t
theObjToAlign.transform = theAnimsouce.transform
// this is the function that aligns the transforms, of the variables
// assigned earlier, it repeats the function as per the loop defined
// above

Thanks for the script!!
Cheers,
David

Your explanation of the code is spot on! (I should have included it as remarks myself, but I thought it was obvious)... Just make sure you use -- for remarks and not // ;)

CGTalk Moderation
11-21-2005, 11:01 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.