Movement On Spline


Its just a quick question. I am creating a sort of “Runner” Game where the player moves along a spline.

My end goal is to be able to have the player switch from center, left and right.

I have 2 ideas which I would be grateful for advice on how to make possible.

Idea 1: Keep just the one spline however jumping from each position (Left , Center, Right) would be controlled by an offset still following the center line just more to the left or right. Im not sure how I can achieve this as my player follows the spline perfectly no matter how i alter vector updates.

Idea 2: Have 3 splines and when the player switches track it jumps to the other spline however I am not sure if this is possible.

If I could get any advice on how to achieve this I would be very grateful.


P.S I code in c sharp, I do not want the player to have full movement just the ability to switch from Left right and center tracks with the keys ASD. Thanks

Splines are a bit tricky as “tavelelled distance” along them may vary a bit depending on the curve of the spline but simply changing between them shouldn’t be that hard.

Supply a variable, let’s say trackFactor which goes from 0 to 1, where 0 is left track, 0.5 is middle track and 1 is right track. Then, calculate the position of each track based of your distance travelled so you get three position, say positionLeft, positionMiddle, positionRight for example. Then, lerp between each position. For example if trackFactor is between 0 and 0.5, multiply trackFactor with 2 so it ranges between 0 and 1, then use that as a parameter to lerping between positionLeft and positionMiddle. trackFactor you’d change based on which track you want the character to move along. I’d assume you’d make a quick lerp or such between trackFactor 0, 0.5 and 1.0 to let the system know which track you want to run along.