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 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.

share|improve this question
1  
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. –  Maik Semder Aug 12 '11 at 10:35
    
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. –  Martyn Aug 12 '11 at 10:46
    
Good point, I understood its gonna be a commercial project that has to ship in time. Your bio did sound like that. –  Maik Semder Aug 12 '11 at 11:02
    
Ah - sorry - I should have said. Very much a work of passion at the moment and no financial rewards on the horizon! –  Martyn Aug 12 '11 at 11:04
    
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. –  dlras2 Aug 12 '11 at 14:44

4 Answers 4

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.

share|improve this answer
    
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. –  Martyn Aug 12 '11 at 13:41
    
@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. –  dlras2 Aug 12 '11 at 13:57
    
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! –  Martyn Aug 12 '11 at 14:17
    
and I added a question mark. :) –  Martyn Aug 12 '11 at 14:18
    
@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.) –  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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.