I’m trying to use splines to develop a grinding system for my game.
I know that I can get both the world direction and world location at a distance along a spline; what I currently aim to do is to get the world location of an overlap with the spline, move the character to it with an offset (so that he is perched above it), then scale the world direction to an acceptable value and use it to Add Force. In this way, the player will be attached to the spline, and then shoved along it with the direction of the shove updating each tick based on the direction of the spline.
Conceptually this is all fine. The problem is, I need to determine the Distance Along Spline value dynamically based on where the player is in relation to it… and I just have no idea how to go about that. The distance along the spline is just a float value and it appears the only way to calculate it (given in BPs, anyway) is based on a given spline point. There doesn’t seem to be any way to trace to the position along a spline in any other fashion.
Am I missing something or is this a fool’s errand with BPs?
EDIT: I may have come up with a solution that involves adding the location of all of a given spline’s points to an array, then looping through that array and comparing my actor’s location with each of the given locations to determine which point he is closest to. From there I can snap him to that point and, because I know that point, determine the distance along the spline which he now resides.
The problem with this solution is that in order for it to work even a little bit smoothly I would need most of my splines to have an exceedingly large number of points, and I’m worried about the performance hit of comparing the actor’s position to potentially hundreds of points along a spline (not to mention the performance hit of having a bunch of 100+ point splines in my level). Surely there must be an easier way?