PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Pathing algorithms.

I was wondering what pathing algorithms everyone uses for their games (for those that require them anyway). The two main ones I know of are;

- A* algorithm; fast if implemented correctly (can be slow and suck up tons of memory if no path is found), and ALWAYS finds the most efficient path.

- Weight system (not sure on name, but basically puts a weight amount on the direction you want to travel in); very, very fast and efficient, takes up no memory, but unfortunately efficient paths aren't always found and NPCs can become "stuck" on walls. I have heard of some successed using this in GBA games.

If the game is simple, the weight system seems to be effective enough. The only thing I don't like about it are "stuck" NPCs, it makes your game AI look dumb and primitive. But hey, it allows tons upon tons of NPCs to move in your game without hardly any slow down.

I'm a little worried about the A* algorithm on PPCs. Does anyone have experience with it? What I'm mostly worried about is the fact that PPCs don't tend to have as much memory as regular PCs do, and attempting to find long paths for many NPCs can outright kill a games FPS. There are, of course, optimization tricks such as waypoints and the like, but still..

Thoughts? Experiences? Anything? :)
I presume you're working on an RPG? :)

Anyway, I'm working on one too and I didn't bother to create path finding for my npcs. They work great using random movements with a little AI to detect if the player is near them. I reckon you'll be using the path finding for the player's character so that he can move to where the stylus was tapped? Mine is completely different because I'm using the hardware buttons for movement this time.

Drop me an email if you're interested, maybe we can collaborate ideas as we move along the development phase.

- Erick
A* is fine and easiest way to implement path finding ;-) I'm using it on my game.

For more info you can browse this website http://www.isometrix.org

Goodluck.
egarayblas:
Yeah I'm thinking of doing an action-RPG (probably could of guessed that from a couple of my latest posts). I've been thinking about a Diablo type combat system (hold down cursor, or stylus in this case) for both movement and combat (Diablo II I should say, Diablo was *click*click*click* I'll just do it where you hold down). But regardless if I do decide on that or the GBA style d-pad controls, I'll still need path finding for NPCs. After all, you don't want them bumping in to each other or walking straight into rocks w/o being able to go around do you?

It sounds to me like you're just using the weight system. I'm curious as to how that's working out? Are you able to get semi-intelligent path finding with it or have you had a lot of problems with "stuck" NPCs? Also have you tried "flocking" an army of NPCs or something across a forest? Or seeing how it works while the NPC is in a FLEE state?
I've been using pathfinding for two projects, and I used A* for both. I naturally tweaked it some.

It's very easy to break A* if you don't understand it completely, or to have it work very strangely. I just converted it to a "node" system instead of X,Y map locations, and I ended up breaking it lots of time during the process.

I have tried other systems, but I got back to A* because it works so well. And it does have a "cost" or "weight" for each tile/node it checks, so you're covered on this front too.

When searching for a path from point A -> B, I found that sometimes it work better doing A* from B -> A instead. While other times it's the opposite. It all depends on your maps and how you use it I guess.

--Eric
I haven't yet implemented all the path finding routines/AI I will need for my game but so far, I can recommend A* as well. I tried it for Tower Mogul and it works great. However, a simple "seek and destroy" AI works well for me (for monsters). I haven't tried "flocking" yet but I've already implemented a "follow the leader" routine so that I'll just assign a leader and all the other NPCs follow that leader. You should also consider NPCs that do melee attack and range attack, its cool. :)

My RPG also plays like Diablo BUT with a twist. I did not use the "tap and move"/"tap to slash" system because I didn't want players to tap their screens endlessly and believe me, some people can actually break their screens just by killing a monster. :) I also integrated an option to control the character by stylus, hardware buttons or a combination of both. This is in preparation for "hardware only" devices like smartphones and symbian devices. :)

If you'd like to discuss more, email me at erick@esoftinteractive.com. I'm afraid I might disclose info about this game as early as now when I shouldn't yet. ;) Sponge may read this and post it at Pocketgamer. :)

- Erick
Steering Behaviors for Autonomous Characters

http://www.red3d.com/cwr/steer/
Since we seemed to have taken a turn for a pure A* discussion, I thought I'd post articles about it (these articles are by professionals in the gaming industry). Also, there may be some who are looking at this thread and have NO clue what we're yappin about;

Your basics (this article actually touches upon other pathing algorithms as well)
http://www.gamasutra.com/features/19970 ... inding.htm

Making it more realistic;
http://www.gamasutra.com/features/20010 ... ter_02.htm

I believe both articles come with a sample program and source.

Psuedocode for A* taken from first link above;

Code:

priorityqueue Open
list Closed

AStarSearch
s.g = 0 // s is the start node
s.h = GoalDistEstimate( s )
s.f = s.g + s.h
s.parent = null
push s on Open
while Open is not empty
pop node n from Open // n has the lowest f
if n is a goal node
construct path
return success
for each successor n' of n
newg = n.g + cost(n,n')
if n' is in Open or Closed,
and n'.g < = newg
skip
n'.parent = n
n'.g = newg
n'.h = GoalDistEstimate( n' )
n'.f = n'.g + n'.h
if n' is in Closed
remove it from Closed
if n' is not yet in Open
push n' on Open
push n onto Closed
return failure // if no path found
Hmmm,

I;ve implemented a A* routine once. It was for PocketAdventures(something i've never finished :oops: ), a JScript SCUMM clone.

The only drawback was that it needed STL, but i found a Pocketpc STL port.
THe routine worked great!

I'll send you the source this week, it was very easy to implement.