A* Pathfinding in Unity

A* Pathfinding in Unity

Code Monkey

4 года назад

357,531 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

nbixel
nbixel - 20.09.2023 23:23

I did this a long time ago in a galaxy far away in XNA, interesting you avoided a Recursive method

Ответить
Ops Ewa
Ops Ewa - 20.09.2023 08:51

Ok but how do i do the same thing without the diagonal path

Ответить
shweta garg
shweta garg - 13.09.2023 10:37

I have done same thing as yours but my grid is not showing up

Ответить
DJ Sikosis
DJ Sikosis - 10.08.2023 05:05

I tried following along with the code but the Grid code has changed since the previous video. So, I grabbed the unity package and got the code from there. I get an error in Testing.cs in Start() with this line -> pathfindingDebugStepVisual.Setup(pathfinding.GetGrid()); NullReferenceException: Object reference not set to an instance of an object

Ответить
Squidlox
Squidlox - 08.08.2023 03:16

these tutorials suck, follow one and new stuff shows up in the next with 0 explanation or what it is or what it does

Ответить
J.G.
J.G. - 20.07.2023 03:26

Thanks for the tutorial! Im using pathfinding for many different objects, so I have the issue that I would need to clone the main grid to a var inside the object each time it has to pathfind, since if two objects are pathfinding at the same time one might overwrite the values of a tile like the F cost, then the other uses that wrong value. Im debating whether I should clone the grid or change the tile object so that it contains a list of H/G/F costs and assign an index to an object. The grid is 90x90, so cloning is quite expensive!

Ответить
BS YT HDD
BS YT HDD - 19.07.2023 08:44

How do i make the unit not move diagonally? i tried to cheat by making the diagonal cost be 99999 but is there a proper way to do it?

Ответить
SilverShield
SilverShield - 08.07.2023 02:22

For people doing this in 2023, do the grid video, then do this video, but you'll have to suffer for a bit with errors and not be able to test. Eventually he shows the code required to test. I can't remember if the generics video was needed, he updates some of the code in that one as well, but I think he eventually shows it here as well. It's very hard to follow. Thank god for chatGPT. Edit - Actually I ran into more issues. Probably should just download the files through the website or move along to another tutorial.

Ответить
Dewzli
Dewzli - 07.07.2023 22:52

Hi Code Monkey

i have been trying to follow your tutorial and i'm having issues with "grid.GetGridObject" because i can't see it anywhere in the grid tutorial or this tutorial and now im stuck because im dealing with a function i have no idea on what it dose

Ответить
Saad Qureshi
Saad Qureshi - 24.06.2023 10:25

What changes will be needed to apply this to 3D?

Ответить
Some_Tiny_Dragon
Some_Tiny_Dragon - 18.06.2023 04:31

Wait, do I need to watch the entire video series on grids to implement this code? You show the first video of the series while that doesn't seem to be enough as I'm running into errors.

Ответить
Daniel Michelin
Daniel Michelin - 02.06.2023 07:06

I'm not sure it makes sense to have the pathfinding algorithm instantiate a grid inside of it. I feel like using dependency injection would result in more understandable and modular code. I also think it would make more sense to have showdebug passed in as a variable.

Ответить
German Bernhardt
German Bernhardt - 29.05.2023 02:34

Awesome tutorial! I'm making a clone of binding of isaac and this worked like a charm! Thank you codemonkey!

Ответить
tomas delgado
tomas delgado - 26.05.2023 02:41

Thank you for this, really helps :)

Ответить
Vi Ma
Vi Ma - 14.04.2023 16:52

Great tutorial. The only annoying thing is that i have to watch 4 videos because the are to much external reference in order to understand 1 single video.

Ответить
Subham Kumar
Subham Kumar - 30.03.2023 09:40

The pathfinding works great on a 20x10 grid but for some reason the character takes a while to think and then move on a 30x30 grid. Any reasons why, how can I alter the code for it to work normally on a 30x30 grid?

Ответить
marscaleb
marscaleb - 23.03.2023 05:18

So wait... This is demonstrating how to create the pathfinding from scratch? Not showing how to implement the already-existing A* package?
I spent so much time watching this before that began becoming apparent.

Ответить
J
J - 02.03.2023 12:07

Hello Sir, I have a question. You use Grid<PathNode> here to create map with pathfinding, but what if I want to use Grid<Sprites> to build a map, do I just new another Grid map?

Ответить
Dogglet Pug
Dogglet Pug - 23.02.2023 22:28

Awesome tutorial man. I've been trying to set up some pathfinding in my game for a while now.

The only thing I'm having trouble with is setting it up to fit a certain area/screen coverage. I know I probably have to do some stuff with the Grid or the camera, but my grid is always partially off screen to the far right unless I make it really small.

Ответить
Eros Guerrero
Eros Guerrero - 21.02.2023 19:49

How could i clean the grid in order to create a new one? I want to create a dynamic size grid to this.

Ответить
tzvika rediano
tzvika rediano - 19.02.2023 20:49

Hey @CodeMonkey, thanks for this gr8 tutorial !
Have a question - where the PNode a & PNode b came from in the CalculateDistanceCost()?

Ответить
Joe Simmonds
Joe Simmonds - 16.02.2023 11:05

Thank you for all your work. You're amazing

Ответить
Jonas Harrison
Jonas Harrison - 16.02.2023 05:07

Bro when did you define the GetNode function, I'm scouring through the video and I cannot find it what the heck

Ответить
Vimux
Vimux - 06.02.2023 15:04

Hello sir, did you do something to make the grid show in the center of the camera? Because I am adding some offset in my main camera inside testing script on start method to adjust it dynamically. I don't know if I missed something.

Ответить
Sungin Jung
Sungin Jung - 30.01.2023 11:35

Yes I would really want to see a video on optimizing the algo..plz

Ответить
Endi HIDIR
Endi HIDIR - 26.01.2023 22:58

If we add "if(_openList.Contains(neighbourNode)) continue;" in foreach, we can pass more cells. But can I ask you is it efficient way for optimization? Or is it possible to cause any bugs?

Ответить
ShadowBoi
ShadowBoi - 21.01.2023 03:16

I am getting a ton of errors because "GetNode" does not exist, what is the code for "GetNode"?

Ответить
ShadowBoi
ShadowBoi - 19.01.2023 04:54

unity: I will give 3d pathfinding
devs: pathfinding for 2d too, right?
unity:
devs: pathfinding for 2d too, right?

Ответить
Wojciech Mysłowski
Wojciech Mysłowski - 17.01.2023 20:31

Hey
I wanted use this script to my project but it is too slow. When enemies chasing player, unity have too many calculations with MOVING player so game crash. I DONT want to use ready internet scripts, i want use my own script created with this tutorial but its too slow. Can i optimize this script without taking too much time? pls help I've been dealing with this problem for a very long time and i dont want to watch more tutorials. I am using unity 2d so nav mesh will dont work.

Ответить
Interloop Studios
Interloop Studios - 14.01.2023 19:38

Where did you write the GetGrid function? I can't find it and it's driving me insane.

Ответить
Sturmfall000
Sturmfall000 - 13.01.2023 20:18

Here's my issue and I have no idea if anyone will bother answering it, but here goes. I am pretty much a total beginner here so forgive my general dumbness--for the character movement bit, I understand the part about being able to return a list of Vector3s. My issue is that I just want to want to move a simple object (like, just a square) along the path, without using your character animation scripts/assets, but I just don't know how to do that. How do I modify this script to make so I can just move a simple object along the path instead of a character? I know it's probably incredibly simple, I just can't figure out how to actually do it due to my general inexperience...
Does the character pathfinding movement handler get attached to an actual gameObject? What script does get attached to the gameObject I want to move? I have absolutely clue. lol

Ответить
Blastgamer77
Blastgamer77 - 20.12.2022 01:39

You forgot to change FindPath from private to public so Testing can use it. You know, if you're going to make a tutorial, maybe use the actual code you showed during the tutorial instead of one you already typed up?

Ответить
Onkar Waghule
Onkar Waghule - 13.12.2022 21:50

in making pathnode class it is not allowing me to make a variable of Grid<PathNode> grid;, help please , in problemmmmmm

Ответить
R3ssoシ
R3ssoシ - 12.12.2022 11:46

Wow this video is gold

Ответить
saleh torkanloo
saleh torkanloo - 01.12.2022 07:04

HI!
I did not understand the benefit of GCost?

Ответить
Charalambos Christofi
Charalambos Christofi - 09.11.2022 19:29

how would you change the code in order to make it not to crash on huge/difficult maps?

Ответить
Shinov Wakamane
Shinov Wakamane - 24.10.2022 23:02

i love when you skip some crucial parts just to make ppl donate/pay you :) lovely

Ответить