A* Pathfinding (E01: algorithm explanation)

Sebastian Lague · 2.3M views · 2014 · 11:39

Open on YouTube

Algorithms & data structuresGame programming & enginestutorial

Why Stack Overflow recommends it

Stack Overflow users link it when someone is new to A* and needs an approachable explanation, or when they are adapting Lague's code to grids, 3D or other languages.

Recommended by 7 people across 7 different months, 2016 to 2022.

What it is

The first episode of Sebastian Lague's game-pathfinding series, explaining how the A* algorithm works with open and closed sets and G, H and F costs. It is a narrated, animated walkthrough aimed at game developers, with companion source code on GitHub.

What people said

Strong rec Gaius Baltar · 2020-09 · Stack Overflow · on “How to make character walk on specific route in monogame?”

You could just make the player character go straight from A to B with some collision on the fences so they don't walk right through. This has the downside of not always working (like when the only path involves walking around an obstacle) and of course requires collision detection to be implemented. The other method is to implement a simple grid-based pathfinding algorithm such as A* mentioned before. A* isn't the easiest algorithm to learn though for an absolute beginner, at least in my opinion, so it helps for sure to watch a good tutorial on the subject. Sebastian Lague made a great video on A* pathfinding [this video] which can really make the algorithm a lot easier to digest.

Recommends Bilal Itani · 2016-03 · Stack Overflow · on “character navigation in unity3d for isometric games”

Here is a playlist about programming A* pathfinding in Unity: [this video] As for the sprite rotation, you could use a sprite sheet that changes depending on the direction your characters move.

Recommends Matthew Page · 2019-01 · Stack Overflow · on “My A* implementation is not correctly keeping track of the "camefrom" map”

I think there is a step missing in the Wiki, when you get the Neighbours you need to be updating their parent (came from) and g values based on the current path (if it is a better path than the neighbours existing path) /* Can the neighbour's g value be improved by coming from this current node ? */ if(neighbour.g > (currentNode.g + ( currentNode.distanceTo(neighbour)*this.wg ))) { /* Yes this is a better path to the neighbour. Set neighbour g to the current node g + distance from current node */ neighbour.g = currentNode.g + ( currentNode.distanceTo(neighbour)*this.wg ); /* Parent node of neighbour is changed to the current node */ neighbour.parent = currentNode; } Sorry, that is Javascript

Recommends Ali Ahmed · 2020-02 · Stack Overflow · on “I want to learn how to implement a* path finding in Python3”

I suggest you first understand the A* algorithm itself, here is a good video i found, check here [this video] . After understanding this, try to code it yourself in whatever language you want and then if you can't understand something ask about that stuff on SO.

Recommends user13241190 · 2020-08 · Stack Overflow · on “Problem with exploring unexplored nodes Astar - Python”

i dont know python but in A* Algorithm one way of backtracing is to Whenever you add a node to the open list set its "Parent" To the current node. So when you add a node to the open list set its parent to the Current node which is the node where it was added from. Then when your adding nodes to the open list and a node already exists in the open list replace its parent with the current node. You should watch this video if you havent already: [this video]

Recommends LuckyBandit74 · 2021-08 · Stack Overflow · on “A* pathfinding algorithm is being semi-greedy”

So I have been trying to implement the A* pathfinding algorithm for a 2D tilemap in Java from this video: [this video] . I tried following the pseudocode and not enough details, I felt, were not explained greatly, especially the idea of the G cost. So, I decided to go into the actual code the video creator wrote and used a lot of his ideas and structure as I had spent a lot of time looking at multiple pseudocodes and not getting the desired result. I understand the code perfectly and going step by step it makes sense, but for some reason the algorithm sometimes is not producing the shortest path. In fact, it is being greedy and trying to reach the end destination early on. Here are 2 examples (Th

Recommends Kim Miller · 2022-03 · Stack Overflow · on “How to calculate diagonal distance on a 3 dimensional grid”

I'm trying to adapt Sebastian Lague's A-Star path finding code [LINK] (youtube) [this video] to 3 dimensions. I have it somewhat working but occasionally the path produced between my nodes is sub-optimal, and I think it's because I'm calculating distance wrong. To move along a single dimension from one node to the next is a distance of 1. To move in 2 dimensions (diagonally) the distance is √2 (which is simplified to 1.4 in the code). These values are multiplied by 10 to keep them as integers, so 10 and 14 respectively. To calculate the distance on a 2d plane you take the smaller of the X and Y distances and multiply it by 14, then minus the smaller distance from the larger one and multiply what

Cites Noam Riahi · 2022-02 · Stack Overflow · on “Create a pathfinder using A* on big terrain”

I try to implement this tutorial of pathfinding using A* and I add a dimension to make it 3d - [this video] my problem is that I have a really big terrain(10km on 10km) with drones(this is why I need a 3d path finder) and a grid on all my map is really heavy so I try to create a "local" grid for every seeker and to do that I first create a "sphere" for every seeker and the I find the closest point on the sphere to the target like that: [LINK] my problem now is to make my grid personal per every seeker, I try to add a instance of my sphere seeker component and then to change to position of the grid to the seeker position but when I do it, the target position is changed. this is my grid script: usi