Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm wondering how to move objects, with rotation taken into account, to follow a curved line

see: http://www.youtube.com/watch?v=iPpO24FeAX4 for an example

In particular I wonder:

  1. how to store the points, how many points to store for a smooth line like that
  2. how to interpolate the curves
  3. how to interpolate between the object and the first "waypoint" along the line
share|improve this question
add comment

3 Answers

Look into Bezier curves and Hermite curves, both of which you can compose into splines. Both usually take the form of a parametric equation where you input a time t between 0 and 1; time 0 would be the start of the spline, time 1 would be the end.

Rotation is a matter of calculating the tangent to the curve.

4 control points for the first segment followed by 3 additional points per additional segment is common for this kind of spline, although some types may want more points.

Note that with parametric splines you often may have difficulty computing position on the spline as a function of distance instead of time, so if you want to answer the question "I've moved X distance, where would I be along the curve" you're in for some integrating. Similarly, instantaneous velocity may vary depending on the density and position of control points.

share|improve this answer
add comment

I've implemented this in my Line-Drawing Game Starterkit and avoided using the over-engineered solutions. You probably need a point every 10 pixels distance, so you can get a decently smooth line without using too much memory or draw calls. Then it's a simple matter of moving the objects from point A to B. To make them appear as traveling smoothly along the path, you simply rotate them to the direction of motion. This is done over time and not instantly, so you get smooth, following a curved line movement without the need to used Bezier curves or similar.

The points are stored in a simple array, inside a Path class that also knows how to draw the path using OpenGL. You can have any number of path points but I would limit them to 50 to 300 depending on the device and required smoothness.

To interpolate the line you should look up the McMaster's Slide Averaging Algorithm (theory).

The object is moving to the first point only when the user has drawn at least two points, to avoid the object spinning wildly. Once moving towards the first point its the same code as moving to the second, third, fourth and so on.

share|improve this answer
add comment

The answer to all 3 is usually splines or some other similar curve.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.