Project on Github

Hi,

I’ve uploaded a project on github that I’m looking for help with.

I want to implement A* pathfinding or some sort of path finding so the enemies will chase the player and avoid obstacles. Its rather a simple project as in the graphics are just some squares and a circle, generated by code. The player is the blue circle and the enemy is the red square.

The project I uploaded isn’t meant to be a game itself, it was design to help figure out pathfinding.

Pathfinding code is in but I couldn’t get it to work correctly. Right now the enemy just wonders around aimlessly.

Pathfinding I got from: Pathfinding code

I appreciate the help! :grin: :sunglasses:

Github project

Thanks!

I can see it hits a wall, and then picks a new direction, not from the direction it came, randomly. I can’t see it actually trying to pathfind.

I put the pathfinding code in the enemy class, seemed logical to me and in Window1 UpdateEnemy method there is Enemy(i).DoOneSearchStep but I commented that out part as I couldn’t figure out how get it to work correctly. Thats is after it finds the path to player, have the enemy follow the path.

Also in enemy class, FoundSolution(), I commented out DrawPath (node) because I don’t need to draw the path. I need the enemy to follow a path.

I did have has Chase (endNode As GridSearchNode) method that was called in FoundSolution, instead of DrawPath. In that I would get the node.mCol, node.mRow and to figure out movement values for the enemy x,y. However I could never figure out hoe to get it to work correctly . So I remove that bit of code.

I haven’t looked at your code, but having implemented the A* algorithm on multiple occasion in multiple languages, I’m quite familiar with it.

The beauty of the algorithm is that it is constantly trying the next best position while tracking where that position came from. In one round it might try position {5, 5}, but in the next round it might try {8, 1} because that’s the next best position given the distance to the target. The algorithm is successful when it finds the target position, and then must backtrack to the start to determine the path.

To create a visual representation of this, you must backtrack from the position being tested on each round. That will dramatically slow the algorithm, but it would be enlightening.

If you think it will help, you can look at the implementation in my Advent of Code project. There are two versions, but the most straightforward is Other Tools/M_Path.FindPath.

Hi Eric,

You’ll find a comprehensive implementation of path finding in my GameKit project on GitHub. The project is a playground and not really ready for production but if you mess around with the demo you’ll see how A* is implemented:

Just make sure you click a tile to place the start (S) and then click the Live Route Finding radio button.

1 Like

Thanks I’ll have to take a look. Thanks.

Interesting, I have to check it out. thanks