Hi!
I’m trying to Lerp the position of an object (2D), however it’s not over a simple line, but a complex shape: in my code, I have an Array of 50 points that make up the “trajectory” that I want my object to follow.
So far, I have tried to lerp the object from one point to another really quickly, however there is a problem: if the game lags/ the framerate is low, the “animation” of the object slows down, this is because the animation is supposed to be really fast and the points are really close together, so sometime in one frame you might want to “jump” several points.
What I would like instead of creating 50 microtrajectories, I can just have a single one for the object to follow.
Can anyone help me?
You need a function that computes where to be given you have traveled X distance along that line of points.
The naive approach assumes nothing about the data and simply considers points N and N+1, sees how far apart they are and uses that distance to decide if you’re between them.
If you are between them, use Lerp to return where you are
IF you are not between them, subtract the distance (From a temp distance) and keep checking.
Everything else is optimizations, such as precomputing and storing distances between segments, storing linear distances at each point so you can rapidly get to it, etc.