Pathfinding with pygame

Pathfinding with pygame

Postby ChristianCareaga » Sat Jun 29, 2013 4:21 am

im stuck! im trying to create pathfinding for me and my friends RPG :P

so we are trying to make the enemy find its way to the player

since the camera is focused on the player which means the player is always at 350,470 but I don't know where to start

anyone have any ideas :D :idea: :idea: :idea:

Here is the code :mrgreen:
https://github.com/linkey11/Necromonster
ChristianCareaga
 
Posts: 52
Joined: Sat Jun 22, 2013 9:54 am

Re: Pathfinding with pygame

Postby Mekire » Sat Jun 29, 2013 5:28 am

Well technically if you want to do it properly you are going to have to learn the A* algorithm.

I just posted an update to my astar study in Completed Scripts here:
[pygame] A* pathfinding demo

You could also try using a library. I have had NetworkX recommended to me as a decent solution. This will however create another dependency for your game making it more trouble for users to run.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Pathfinding with pygame

Postby ChristianCareaga » Sat Jun 29, 2013 6:01 am

Mekire wrote:Well technically if you want to do it properly you are going to have to learn the A* algorithm.

I just posted an update to my astar study in Completed Scripts here:
[pygame] A* pathfinding demo

You could also try using a library. I have had NetworkX recommended to me as a decent solution. This will however create another dependency for your game making it more trouble for users to run.

-Mek


I looked into that a bit but it looks kinda hard guess im gonna have to try it
ChristianCareaga
 
Posts: 52
Joined: Sat Jun 22, 2013 9:54 am

Re: Pathfinding with pygame

Postby Mekire » Sat Jun 29, 2013 10:21 am

Well depending on your needs it might be over kill for you.

If your enemy agents are restricted to motion in four directions (up,down,left,right) then you can easily figure out (from the vector between the enemy and the player) which direction(s) would bring the enemy closer.

So a naive approach would be:
Code: Select all
1. find the directions that reduce distance between player and enemy.
2. test if these directions are unoccupied by obstacles.
3. If a tested cell is unoccupied then move in that direction;
    else pick a direction that doesn't bring you closer and move that way.

This will create an enemy that tries to chase in the direction of your player when possible. It will however be completely incapable of maneuvering around obstacles intelligently. If this is sufficient to your needs, then try it. Otherwise yes, you will have to learn about actual path finding algorithms.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Pathfinding with pygame

Postby ChristianCareaga » Sun Jun 30, 2013 9:00 am

My partner actually figured it out using A star

there is still alot to do to make it better but the enemy does find its way around obstacles and to the player

tell us what you think

https://github.com/linkey11/Necromonster
ChristianCareaga
 
Posts: 52
Joined: Sat Jun 22, 2013 9:54 am


Return to Game Development

Who is online

Users browsing this forum: Google [Bot] and 1 guest