How to Do PATHFINDING: The Basics (Graphs, BFS, and DFS in Unity)

preview_player
Показать описание
This is the first video in a mini-series on PATHFINDING I will start and finish for the month of May. We go over basic graphs, DFS, and BFS in a quick, conceptual way with code examples in Unity.

My goal is to post on Monday's, but at a minimum there will be 3-4 videos out by the end of the month... I'm challenging myself here :)

Also if this is too fast for some of you, feel free to ask questions in the subreddit (linked below) as they can get lost in the comments, or feel free to click the Github link below and step through the code slowly on your own machine. If it's too slow, we'll ramp up to more advanced use cases later on.

Рекомендации по теме
Комментарии
Автор

I have been trying to implement BFS all flippin day and was making the mistake of using a stack. Thanks for showing and explaining the difference of both. I changed one word and magic haha.

In my case, I changed pop() to shift() as I was making a JS implementation.

Thanks again!

IsaacHisey
Автор

My 3rd test in Data Structure will be pathfinding so i'll follow this video series real close. Rock it on, ma'lady

MatheusLB
Автор

You know, i'm nowhere near ready to use this kind of code, but the logic behind it is amazingly helpful and informative. So glad i subbed :3 Looking forward to the rest.

keeperoflenneth
Автор

I'm so excited for this! I've started learning pathfinding recently, approaching it (initially) as something that should have been simple. I quickly found out, after skimming several PHD theses, it's not simple :P

DanTube
Автор

I really enjoy your content (I think that you are some kind of a code deity as a matter of fact). I think the topics you are covering here are really intriguing and I can understand their importance for coding in general and game dev. in particular. Having said that, I would have liked a more structured presentation on bfs/dfs (especially how visit order matters-I know you repeatedly referred to it esp. when discussing queues and stacks). I feel it would have been more educational to have had more detail there. Thanks a lot and I'm looking forward to the other videos in this series!

mpertalulaki
Автор

For clarity: TheHappieCat pronounced _dequeue_ as "day-queue, " and it may be clearer to some pronouncing it "dee-queue" instead, indicating the item is "_un-queued_" from the queue.

I'm really glad you included the caveat for BFS & weighted paths. Adding an extra step to tally up the total distance (accumulated weight) of each of the possible paths, finding shortest, would be one possible method for these.

jeroldhaas
Автор

Hello! I have watched your video and learned a lot from it. I made my own pathfinding script and it works perfectly at play. Then when I update the map (obstacles that the script has to avoid, change) the script doesn't recognize them. Is there anything I should edit from your original script so it would work in an updating map or is this just my own mistake?

Thanks!

EDIT: just solved it. If you have the same problem make sure you format all of your lists every time you call your pathfinding function :)

ouzerX
Автор

love your content, please keep it up!

arthurviniciusalvessantana
Автор

What if you first determined on which direction of the agent is the goal, and used that value to search first with DFS. Let's say agent is at coordinates (0, 0) and the goal is at (10, 5). The algorithm will first compare the two coordinates to determine on which direction the goal is. In this example it is further on the positive x axis and closer on the positive y axis, so we'll prioritize moving right (for getting closer on the x axis), up (for getting closer on the y axis), left and down. In most cases, I imagine this would be more efficient, but this would not guarantee the shortest path in some complex node web that the shortest path involves going away from your target first. Although this kind of approach will resemble very much how we, humans do pathfinding. Also, you could recalculate how far away on each axis you are to prioritize stack placement each turn, but I don't think there are a lot of scenarios where this would help.

craftmechanics
Автор

Null Reference Exceptions are the bane of my existence....

kyleprince
Автор

its to late to watch the video, just pass by to say thanks for another video, goin to watch tomorrow. have a nice day and keep the good work, love the videos.

OldEstatica
Автор

This is the best explanation of the queue and stack i have ever found. I wish my teacher could explain things like this XD
interesting video, and thanks a lot :)

yougotOWENd
Автор

So what does this look like when the goal changes position every step?

toomdog
Автор

I just coded A* pathfinding like a week ago, damn shame this video didn't exist then haha

PsychoEverything
Автор

I found the shortest path between wherever my mouse was and the like button!

bagandtag
Автор

After May, would you mind doing some tutorials of Unity in general? I really need help.

akshayazariah
Автор

Dijkstra can also use heuristics and be identical to a-star by adding the difference between heuristics of each node the the cost of the path between the nodes. Are you also going to look at dynamical programming algorithm? Because you can pre-compute this and then use that policy from any point to a given end point (or from a given start point to any end point).

kwinvdv
Автор

Does your plan for this series include ways of doing this in a 3D enviornment? I've used a system just like this in a game that only requires 2 dimensions of movement before, how would you then expand this to 3D enviornments?

knightshousegames
Автор

can you recommend some books of game programming?

lofiprogrammer
Автор

do you recommend learning c++ first.. I tried to learn c# but there are no good books with exercises like c++ primer or accelerated c++ or java beginners sun press

jrlcgmx
join shbcf.ru