Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Figuring out where we are on a curvy path

$
0
0
So, I'm kinda confused about how I should create, store (in structs at runtime), and interpolate along potentially curvy paths. Suppose I have a path of, say, ten points. And I want to move an entity 200 units along that path. Those ten points aren't an equal distance from each other, even linearly. How do I know where 200 units into the path is? If I have a vector of ten points, how do I know 200 units of movement along that path lies between point 6 and 7? I could store the distances between each point *also*, and do: float segmentDistance = totalDistanceThrough; size_t i = 0; while(segmentDistance > pathSegmentLength[i]) { segmentDistance -= pathSegmentLength[i]; ++i; } We are between: pathPoint[i] and pathPoint[i+1], ...but the iterating over every path segment length subtracting from the distance seems dumb. I'm pretty bad at math, but there has to be a more elegant way. What's a better more-common way to store paths and move along them? For example, what information do you store alongside your path control points?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>