• entries
743
1924
• views
584744

# Curves

452 views

Need to start updating here a bit more often really so no screenshots today but I've sort of managed to get smooth tracking along my multisegment curves working in the game.

It appears it is actually quite hard to get constant speed along a bezier but I'm not too worried given the usage I need.

The basic idea is that the curve is stored as a sequence of points, each with an associated control point, the control point of the last point being unused, and storing the pre-computed length of each curve with each point.

The class that looks after this data then returns a point based on the input of a distance along the curve.

First, easy early outs. If distance<=0, return the first point. If distance>=total length, return the last point and signal that we have completed the path.

For the rest, start by copying the required distance to a variable remainder. Then loop through each segment. If the length of the current segment is less than the remainder, deduct the length from the remainder then move to the next segment.

When the segment length is greater than the remainder, we have the segment we need to examine. We can then divide remainder by the segment length to get a value between 0 and 1 along the relevant curve.

Then just call the Bezier function on the current curve to get the position.

I've tested this with a cloud moving around a curvy path and seems to work okay apart from the constant speed issue but a bit of googling suggests this is not simple to solve - sampling along T on a curve does not return equidistant points - but I don't really care.

Making the camera follow a curve is more a UI and interface problem now that the actual maths is proven to work so more a ponder in quiet moments problem than a grapple with numbers issue.

That's the exact same mechanism I ended up using for Procyon's enemy flight paths, to get constant speed :)

Glad I'm not the only one that backed off of the ideal of pure curves and went with subdivided line segments instead :)

Glad great minds thinking alike [smile].

You're updating your journal even less than me at the moment. What are you up to? And where the hell is Milkshake? Bought an island off the iPhone sales of Melon Golf and given up gamedev I reckon.

Hmmm, I don't have them to hand but I'm pretty sure one of the early Game Programming Gems books had some stuff about following curves in it, including moving at a constant rate..

I'll have to check when I get home (provided its the right side of 11pm when I get home that is..)

Quote:
 Original post by phantom Hmmm, I don't have them to hand but I'm pretty sure one of the early Game Programming Gems books had some stuff about following curves in it, including moving at a constant rate.. I'll have to check when I get home (provided its the right side of 11pm when I get home that is..)

That would be appreciated, cheers Phantom.

Quote:
 Original post by Aardvajk Glad great minds thinking alike [smile]. You're updating your journal even less than me at the moment. What are you up to? And where the hell is Milkshake? Bought an island off the iPhone sales of Melon Golf and given up gamedev I reckon.

Hah...I guess I should probably update my journal ever again, eh?

## Create an account

Register a new account

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.