Random motion

July 2nd, 2006

I tried several ways of creating a smooth random motion and found the following approach quite good.

The basic way of randomly moving a point on the plane is to select a position somewhere on the plane and move the point toward it.
The idea here is to do this separately on the x and y coordinates.
A new x position is chosen somewhere on the plane.
We start a new tween with a duration based on the distance between the original position and the new one.
When the tween is complete we select a new position and start a new tween again.
Because we do that separately for x and y the speed is not synchronised between the two directions. As a result we have some nice curves.

A problem with this approach though is that it's not possible to define positions you want the point to go through. Splines are more appropriates if you need this feature, otherwise, this trick is easy to implement and gives good results.