Notifications
Clear all

[Closed] Align an object to an animated object

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
5 Replies
1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

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…

Can you use a script controller on the objects transform? something like:


dependson $teapot01
$teapot01.transform

or maybe wire parameters.

J.

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

1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

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 //

 PEN

How about just using constraints? Would this not be easier?