The GEN_SplinePartrol.charScript does this by default. You can either use that script directly, or unpack unpack the appropriate pack file (probably Shared.pak) to have a look at how it works.