I'm planning my first game and am planning on using the engine set out in Beginning Android Games, as it deals with a load of stuff that is just noise at the moment to me (because I've no real world experience yet). There's no real time restraint - this is a learning experience more than a real world project, although I would love to be able to release something at the end of this project.

The way the book tells me how to do movement has been very much acceleration and velocity based with other forces thrown in (wind, gravity etc) but it's not covered how I can set a predetermined path for an enemy to follow. I was thinking that I could use a lookup table to map points for the enemy to head for, and then I'd just need a way of smoothing out the turning so that the motion is fluid. Is this the correct approach?

I know this is a bit of a vague question, and I would give you some code, but I'm very much in the planning phase at the moment, so I'm just looking for some pointers or things to think about whilst I'm trying to work out how it's all going to hang together.

  • 1
    \$\begingroup\$ Don't use such an esoteric engine. One of the advantages of using a more common engine is that it has more users, which leads to more tutorials available in the internet, you will get more specific help with the engine from other users. Moreover it's better tested and hence has less bugs. Good engines have user forums where you can ask details. Take such an engine, not an esoteric one. \$\endgroup\$ – Maik Semder Aug 12 '11 at 10:35
  • \$\begingroup\$ But the point is that I don't want to use an engine that does everything for me as I want to learn how it all works eventually. Using this engine will allow me to get a few basic things done for me, which I can then go and change and learn as I go - using a fully fledged engine will leave me no room to tweak or change things as it'll prob be too large for me to understand. I don't want to just consume - I want to learn and understand and hopefully contribute at some point. \$\endgroup\$ – Martyn Aug 12 '11 at 10:46
  • \$\begingroup\$ Good point, I understood its gonna be a commercial project that has to ship in time. Your bio did sound like that. \$\endgroup\$ – Maik Semder Aug 12 '11 at 11:02
  • \$\begingroup\$ Ah - sorry - I should have said. Very much a work of passion at the moment and no financial rewards on the horizon! \$\endgroup\$ – Martyn Aug 12 '11 at 11:04
  • \$\begingroup\$ Could you give a little more information regarding why you want enemies following a path, as opposed to simply pathing to a point on their own? Are you thinking about things like patrolling, or way points? Either way, you should pick certain points on the map, and simply use a path finding algorithm to get to the next point in your queue. \$\endgroup\$ – dlras2 Aug 12 '11 at 14:44

Here are some resources to get you started:

You can find more on Wikipedia, which has some good articles on specific algorithms, and of course Google. Once you start investigating a little more, feel free to post more questions specific to your implementation.

  • \$\begingroup\$ Hey - thanks for your answer, but it's not actually what I was looking for. My question is more to do with following predetermined paths, rather than path finding. \$\endgroup\$ – Martyn Aug 12 '11 at 13:41
  • \$\begingroup\$ @Martyn - It's a little hard to tell your intent since you never actually asked a question. (Seriously - it's hard to ask a question without using any question marks.) At the very bottom of Amit's article on map representation, he talks about way points. Following a path is essentially path finding to specific pre-determined way points. \$\endgroup\$ – dlras2 Aug 12 '11 at 13:57
  • \$\begingroup\$ Yeah - sorry. It's kinda difficult as I was trying to get some info on the best way of approaching the subject. thank you for your answer, I will go read those articles. Like I say, I'm very new to this and appreciate your help a lot. Hopefully I'll be able to ask (and answer) questions more precisely in the future! \$\endgroup\$ – Martyn Aug 12 '11 at 14:17
  • \$\begingroup\$ and I added a question mark. :) \$\endgroup\$ – Martyn Aug 12 '11 at 14:18
  • \$\begingroup\$ @Martyn - In general, if you can summarize your question in the title, you've got a good question. I took the liberty of editing your title (about the same time you edited your question.) \$\endgroup\$ – dlras2 Aug 12 '11 at 14:41

This tutorial at XNA Resources shows one approach.

Basically, you store your waypoints as a queue of coordinates, then move the entity toward the first point in the list. Once you reach that point, remove it from the queue and continue to the next point. Depending on your game, you might want to set some limits on how quickly the entity can change speed/angle so the corners aren't so sharp.


You could use a steering algorythm, giving the entity a (set of) goals/waypoints and let the entity manage itself, considering its position/velocity/acceleration and its goal.

  • The avantage is that is easy to go from a static waypoint to a mobile target :)
  • The inconvenient is that its not really a pathfinding, and more a local search : the entity react to obstacle, but does not search the map (to avoid ntering a cul-de-sac for exemple). You may have to add some waypoints using some higher level reasonning (ie high level pathfinding to get the waypoints, and low-level steering to go from one waypoint to another one)

There are some good algo and exemples here, with differents method.


I'd suggest creating a list of cubic Bézier curves for each unit to follow. This will give you nice smooth paths.

To join multiple curves into a single curve smoothly, every control point at which two curves join must be on the line between the two control points on either side.

They only difficulty with them is that maintaining a consistent speed of travel requires a bit of extra work. One way to achieve that is to do a binary search each frame to find the new value of the curve parameter required to travel a specified distance.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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