# How to control object's path follow speed based on its position

I am trying to animate a rollercoaster. For now I have a cube following the Bezier path of the track. I need the cube to change its follow speed based on its height. (the higher it is, the slower it is).

How do I control follow speed based on the height of the object? Keyframing is not an option as the relationship is too complex.

I tried this with animation nodes, however height is affected by position on curve, which is affected by speed. Trying to control speed by height creates a paradoxical loop. Is there a way (in animation nodes or otherwise) to use the cube's current height, to determine its rate of change of position on the curve in the following frame?

Sidenote: I have an expression for speed (from physics energy formulas): speed = (200 - (2 x height))^0.5

One way to do it is to use a discretized implementation instead of a parameterized one. We store the parameter (location along spline) of the object in a custom property. At each execution, we increment that parameter by the velocity that we can compute from the relation you provided above.

The divide node is a unit conversion which you can replace with whatever you need. Note that Uniform has to be used when sampling the location for obvious reasons.

A useful addition is to add a condition where the parameter is set back to zero whenever the frame is equal to or less than one so that you can play the animation as much as you want.

A similar condition can be added to cube location.

• Your answer seem good but I don't have the level to fully understand how to replicate your method. What is "parameter" in object attribute nodes ? Oct 14, 2020 at 15:21