I'm using a series of easing equations to make menus and transitions a little more interesting in my first game. That got me thinking about how game objects (enemies, NPCs, spaceships, whatever) are 'scripted' to move along complex paths. I'm no maths guy, but I've read that paths can be plotted using Bezier curves (define 2+ control points, interpolate to get position values using start, change and duration values). However I'm not exactly sure how to best go about this (in a structured way that works for a variety of different motions).

I already have a bunch of tweening functions, but these are relatively simple linear, quadratic and cubic curves.

An example - say I wanted enemies to appear at a certain point, then spin in an archimedes spiral until they were off-screen. How would this be best accomplished, and indeed, made generic enough so that another enemy of the same type could move along a sin wave-esque path instead?


2 Answers 2


Suppose the curve you have represents a path of motion (such as fly forward, arc left, arc right). A simple technique in a shoot'em up is to build from these motions, and chain a list of motions into a maneuver. Then chain maneuvers together. Any ship can perform the maneuver. This way you can reuse a library of motions and maneuvers with any combination of ships.

For classic shoot'em up formations of ship, you could chain the ships together so that one ship appears to be following the next, when it spawns at the same position a little later.

For example, look at 'motion', 'maneuver', 'formation' in this C++ code: http://finegamedesign.com/euphonics/glyrus_behavior.cpp

My code was from Euphonics, a shoot'em up with aliens that changed directions on musical cues. This was a student project with other programmers at USC. Windows demo of these motions is here: http://finegamedesign.com/euphonics

  • \$\begingroup\$ +1 You finished typing yours before mine and I was going down the same path. I will also mention however that using this technique you can also do things like "Wait at x position y seconds" as a maneuver, which you wouldn't be able to do with mathematical paths alone (or at least not easily) \$\endgroup\$
    – Lunin
    Apr 16, 2012 at 21:56

This may not be the best idea, but you could probably define the direction and the speed (if it's not constant) in two different splines. Splines are extremely versatile and their value in a single point is extremely easy to calculate.

The downside is that you may have to write a separate tool that allows you to design a path and creates the spline for you by interpolation.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .