Hello! I need help with converting my spline movement from (mostly) one axis to two axes. My current system was designed for a sidescroller, but I’m interested in developing a system that will allow the spline to wrap around! It’s a little difficult to explain so I included a couple diagrams.
Currently the spline + camera system works in one axis.
It starts with a mouse click: the camera shoots a projection for the mouse’s position into space (fig. 1). Taking into account the Z offset of the camera (from the character) it determines a point that will be fairly close to the movement spline. The character then compares this target point’s X against its own X. Every tick it asks: Is this X greater or smaller than mine? It then knows to travel up or down on the spline. If the Xpos is greater, move higher (to the right) on the spline, and vice versa. It’s very straightforward because the character will always be traveling left or right and comparing against the Xpos. There is also a cushion range (of about 5 or 10) to give some leniency when the character approaches the value and doesn’t overshoot.
- How do you calculate a target point (that’s fairly close to the movement spline) in two axes? (fig. 2)
- Even if you do have a target point in space, how can you compare the character’s position against the two axes (both X and Y)? If X is greater, it doesn’t always mean move “up” the spline–in fact, if there is a loop, it will actually mean the exact opposite on the other side of the loop. So how can the character know they should move “up” or “down”? using the camera’s vector from their position?
- What is the best way to determine a “cushion range” that will make sure that the character appears to accurately walk to the target position? If the X or Y is too lenient with its comparison the character won’t appear to move to the correct position. If it’s too tight the character will glitch out and appear to get stuck between two points thinking it will need to move up or down.
I appreciate any pointers!