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:
It’s not a problem at the beginning of the path, but the farther along it goes, the greater the problem gets.