i'm trying to figure out keyframes in MAXScript. I have a script that spawns dummies and creates keyframes to move them along a spline at a given speed. I am updating the script after someone else wrote it years ago and it makes sense for the most part but I am having troubles executing on my wishes.
The script places dummies and then the speed at which the dummies travel along the spline goes like this:
miles = pathlngth/5280.0 -- length of path in miles
framecount = 0
framecount = (miles/carspeed.value)*60*60*30
Makes sense to me so far. Then we get down here:
--Make initial Dummy at 0%
newDummy = dummy size:1
WorldAlignPivot newDummy
newDummy.name = ("D_" + drivePath.name as string + "_001")
newDummy.pos.controller = path follow:true
PosCntrl = newDummy.pos.controller
PosCntrl.path = drivePath
PosCntrl.axis = 2
PosCntrl.percent = 1.0
PosCntrl.percent.controller.keys[2].time = framecount
PosCntrl.axisFlip = off
PosCntrl.constantVel = on
PosCntrl.axis = 0
setBeforeORT (newDummy) #linear
setAfterORT (newDummy) #linear
From what i can gather here, PosCntrl is setting the "percent on spline" value to the framecount number to get the slope needed to allow the dummy to travel at the given speed. This causes the curve editor to look like this: image of curve editor with Linear ORT
Notice the interpolation becomes a dotted line after the second keyframe. I want to, in code, add a keyframe at the end of the animation along that interpolation line. You can do it by right clicking and pressing "add keyframe" in the curve editor itself, but i want to make it automatic. When attempting to do so with this line of code:
--previous code block goes here
addNewKey newDummy animationRange.end
I get this result in the curve editor: post addNewKey attempt
I understand, i think, why i twould do such a thing. But it's not what I want. please help!
Found the answer. I was doing my ratios wrong. Turns out, you can set the desired value in a keyframe controller, get that value, and then multiply it by the ratio you used to change the location of the keyframe itself. Explanation below, and if you know a different way please post it here!
As you can see, it was as simple as figuring out the original value and multiplying it by the ratio. Simple mathematics that took my a day to remember and I may or may not be ashamed of it lol.
I hope this helps anyone else who is struggling with maxscript!