View Full Version : Animate based on rate of change?

07-16-2018, 08:58 PM
Is there a way to set up an expression (or other approach) to animate an objects Z value based on a rate of change?

So lets say I create a Master Control number channel named Rate and I set it to 1.
I then want to tell my Mover object's Z to add a Rate of 1m to it's current position on every frame...
So come frame 100 Mover's Z = 100, at which point I want to spline curve animate Rate from 1 up to 3 on frame 150...
So on frame 101 Mover's Z would step a Rate of 1.02,
and on frame 102 it would add a Rate of 1.06,
and so on...

I think I'm explaining the concept, or at least have it in my head pretty clear, but I don't know enough about the syntax of expressions to set it up...?

Basically, each frame, Mover's Z adds the Rate to it's Z from the last frame?

Help is appreciated as always...

07-18-2018, 02:22 PM
I don't think you can use an Expression to do this, since I don't think Expression have any way of storing data from frame-to-frame (e.g. the previously calculated position), and no way of looping through all the prior Envelope-based values of the Rate Master Channel if you directly position to a random frame.

You could write a generic LScript to calculate the position for a particular frame, but if you use the Position(X,Y,Z) LScript command, it would create a keyframe at that frame. You could possibly write a Master Plugin LScript that would create keyframes for each frame by adding up all prior values of the Rate MC (basically baking the motion).

I think to modify the Object's motion without creating keyframes, I think you'd need to write a Motion Object Handler LScript to calculate the current frame position by adding up the Rate Master Channel value for each prior frame. I think it would have to be recalculated from Frame 0 for every frame because of the spline-based change in the "Rate" Master Channel.

And now, for something completely different: :)

I think this may fall under the general question of "What are you actually trying to do?" This may be a case where Bullet Forcefields might work for you and actually be easier to set up. Sorry if I missed the point entirely, but here goes:

When it comes to velocity (per-frame change in position), the "rate of change" in velocity is usually acceleration. So, some force was applied to your object, causing acceleration, and the force was then removed / stopped (dropping the acceleration to 0.0) when the velocity was equal to 1m/frame. Then, at frame 100 in your example, a different force was applied to accelerate the object up to 3m/frame at frame 150 and then removed.

According to basic physics equations, v = v0 + at, or in words, the new velocity equals the initial velocity plus acceleration multiplied by time. So, using 30 frames-per-second for calculations, if you have a ball with an initial speed of 0.0, apply an acceleration of 30m/s/s for 1 second and remove it after 1 second, the ball will be going 30m/s, or 1 meter per frame at 30fps.

If you then want to increase the velocity to 3m/frame over 60 frames (to make the describing it a little easier than 50 frames), or 90m/s with an initial speed of 30m/s you'd apply an acceleration of 30m/s/s and then remove it after two seconds, resulting in a velocity of 90m/s, or 3m/frame. To get the same velocity over only 50 frame, apply a larger acceleration of 30m/s/s * (6/5), or 36m/s/s.

A sample scene using a Bullet Forcefield to accelerate the BlueBall is attached. Gravity is set to 0.0 in all dimensions, and the ForceField is set to type "Acceleration" and has an Envelope for turning on and off the acceleration (in real life you'd have to calculate the Force required based upon the mass of the object to get the desired acceleration).


If you look at the ball's successive Z Position in the numeric input fields, with the Bullet calculated acceleration / velocity the BlueBall isn't going *exactly* 1m/f after frame 30, but very close, and isn't going *exactly* 3m/f after frame 150, but again, pretty close.

Again, sorry if I missed the point, but fun (for me) to work it out.