# Problem with on-rails shoot 'em up type movement

I’m trying to make a game where you move forward along a fixed path, but can freely move up, down, left, and right, similar to something like StarFox or Panzer Dragoon. I have a spline that a pawn follows, and I accomplish the player’s vertical and horizontal movement by moving the spline points along their up and right vectors. That part works perfectly.

What isn’t working is my solution to the changes in the spline’s length after moving it. What I’m doing is getting the original un-altered spline length (originalPathLength) in BeginPlay() and keeping the pawn’s distance (distAlongPath) along the spline a separate variable that’s unaffected by changes in the spline, then do this in the pawn’s Tick():

(MoveAlongSplinePath() just set’s the pawn’s position and rotation to the passed distance along the path.)

``````// Adjust the plane's distance along the path to account for path length differences after
//	moving the spline points
float currentPathLength = splinePath->GetSplineLength(); // The length of the moved spline

// The adjusted distance along the path
float movedPathDist = currentPathLength * (distAlongPath / originalPathLength);
MoveAlongSplinePath(movedPathDist);
``````

The idea is to find the percentage distAlongPath is along the original path length and then moving the pawn that percentage along the current path length so that it’d stay in the same general area.

The problem is that it does not seem to be working. Instead this is happening:

http://i279.photobucket.com/albums/kk144/jacen91/20170602_183002_zpsdiah4b4y.jpg

It’s not a problem at the beginning of the path, but the farther along it goes, the greater the problem gets.

instead of moving the spline, you should keep the spline where it is, and just move the pawn to a location offset from the spline, based on up vector and right vector.

That’s how I originally planned on doing it, but I figured it would cause problems with tight turns so I came up with my above idea without fully thinking it through.

I really should have just done it that way to begin with.