02-06-2015, 07:05 PM
In other words you want to find the spline position that matches the same Z "depth" as the player, right? The best solution for this depends on the number of enemies, i.e. you should test different approaches for their performance. Ideas:
- Alter the enemy until the Z-delta (between player<->enemy) is near zero. If you use InterpolateFast() you'll only do lerps, so this should be reasonable fast. Sort of brute force approach
- Use GetNearestSplineTF() to get the spline point nearest to player. Could get wrong results depending on the curve, though. To speed it up, check the segments bounds and use GetNearestSplineTF only against those segments within near distance
I would stick to the first idea. You can further optimize it by iterating manually over the cached points (stored in CurvySplineSegment.Approximation[]) and compare their Z, then lerp between the two nearest points.
- Alter the enemy until the Z-delta (between player<->enemy) is near zero. If you use InterpolateFast() you'll only do lerps, so this should be reasonable fast. Sort of brute force approach
- Use GetNearestSplineTF() to get the spline point nearest to player. Could get wrong results depending on the curve, though. To speed it up, check the segments bounds and use GetNearestSplineTF only against those segments within near distance
I would stick to the first idea. You can further optimize it by iterating manually over the cached points (stored in CurvySplineSegment.Approximation[]) and compare their Z, then lerp between the two nearest points.