[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Pathfinding



Hey Yanom,
     Hmm... your game is "probably not" tile-based? sounds like you aren't very far along yet... I think you may be worrying a bit too much about pathfinding now. The truth of the matter is there is no single solution to pathfinding. There isn't even a best solution. There are some common tools for pathfinding that are well used, which it's nice to be aware of, but you're never gonna have something that works like:

  import pathfinding
  pathfinding.findpath(character, destination)

All the little bits about how you represent your world, facts about what objects are in it, details about how you want your game characters to behave, design choices about their style of movement, how difficult you want the gameplay to be, all this stuff and more has a huge effect on how you'll want to do pathfinding. And you know what? _that's a good thing_ cause all those little facts are opportunities to cheat and hack and exploit things in smart ways.

My real point is that right now, without knowing what you want to do with the game and the world, it's hard to figure out what you want to do with pathfinding. However, when you have a world and a character and all that, it's actually pretty darn easy.

My advice to you is to *trust yourself* that when you've actually got a character that's moving, and getting stuck in some pit trying to get to his destination, that you'll be able to figure out a good solution to that. If you're worried about making bad choices now and walking into this horrible un-pathfindable case cause you didn't figure it out now, well don't worry. Most every problem has a good and fairly simple solution, if not, all code is refactorable, and for cases where it's too much work to refactor, then making mistakes is a great way to learn.

So go program what you want until it's not working - you'll be able to fix it! and it will be a lot easier than things seem now.

----
anyways, now back to chatting on the list about pathfinding... :)

One fun solution to path-finding that has been good for me when there is no grid has been a "visibility" approach. Basically you do a collision check for the character going from where he is straight to the goal. If you find that he'll collide with something, then you "turn" till you've cleared the object, and do a collision check for moving past it - if the path is clear to move past it, then that becomes your next way point, and you do the original check towards your goal. If, however, you end up hitting something else trying to go past the first object, then you do the turn test on it, and so on till you get a waypoint.

The trick to it is that when you find you'd hit something, there are 2 ways to turn, left and right. What this means is that for every object there are 2 choices, and each of those 2 choices may result in another object you'll have to pick between. What that means, is now you've got a search space to start exploring.  You'll have to decide between trying left or trying right, and each choice leads to more choices. Boom, now you've got a place to use A*.


On Tue, Jan 27, 2009 at 3:48 PM, Yanom Mobis <yanom@xxxxxxxxxxxxxx> wrote:
my game is 2d, but probably not tile-based.


Attachment: pathfinding_sloppy_sketch.png
Description: PNG image