A* Pathfinding (E02: node grid)

  Рет қаралды 637,632

Sebastian Lague

Sebastian Lague

9 жыл бұрын

Welcome to the second part in a series on pathfinding in Unity. In this episode we look at how to create the grid of nodes required to begin using the A* search algorithm -
(explained in detail in part one: • A* Pathfinding (E01: a... )
Source code: github.com/SebLague/Pathfinding
If you'd like to support these videos, you can do so with a recurring pledge on Patreon, or a one-time donation through PayPal. / sebastianlague
www.paypal.me/SebastianLague

Пікірлер: 547
@synvian8212
@synvian8212 8 жыл бұрын
I could listen to this guys voice all day, strangely relaxing . . .
@eleos5
@eleos5 5 жыл бұрын
Not me, for sure!
@louissherwood5221
@louissherwood5221 4 жыл бұрын
he pays hugh grant to do his voice overs xD
@peterbengtson7406
@peterbengtson7406 4 жыл бұрын
@@louissherwood5221 He has a far posher voice than Hugh Grant, though: he pronounces "off" as "orf" and "gone" as "gorne", for instance, and I suspect he would pronounce "hour" as "ahr" and "flower power" as "flahr pahr" (so-called triphthong smoothing). A very pleasant voice speaking Conservative RP. Not that usual nowadays.
@joshual3486
@joshual3486 3 жыл бұрын
@@peterbengtson7406 To me it's really not RP, it's more from mainland Europe (pretty sure he's Danish)
@gobblestheturkey1413
@gobblestheturkey1413 3 жыл бұрын
A* asmr
@Garbaz
@Garbaz 9 жыл бұрын
17:00 (a + b/2) / b = (a/b) + (b/(2*b)) = a/b + 1/2 [ = a/b + 0.5 ] And calculating "a/b + 0.5" is easier for the PC than "(a + b/2) / b".
@SebastianLague
@SebastianLague 9 жыл бұрын
Good optimization, thanks for pointing that out.
@MrMineHeads.
@MrMineHeads. 6 жыл бұрын
why the fuck would you do that? this is a float.
@scholes8734615
@scholes8734615 6 жыл бұрын
Not the same fact
@brainlow
@brainlow 6 жыл бұрын
I'd like to add one more thing about this for anyone else who scours the comments for tweaks - three years late, i know, but these tutorials are phenomenal and i've been going through them. I've learned more about A* than I ever thought possible. Mathf.RoundToInt((gridSizeX-1) * percentX) is almost right, but not quite. By subtracting 1 before multiplying by the percent, you won't go over the number of squares that exist, but you'll be getting a percent of an incorrect number. If you have a grid with 100 or more squares, you may eventually encounter situations where you are off by a square. Also, you need to you FloorToInt, because assuming 0 is the left-edge of the grid, it's also the left edge of the first square. 0.5, then, would be the middle of the first square, and so would 0.9, 0.99, and so on. If you ever round up, you can be inaccurate by as much as half a square. So instead what i've done is Mathf.FloorToInt(Mathf.Min(gridSizeX * percentX), gridSizeX - 1)
@QuestionMark43
@QuestionMark43 5 жыл бұрын
Did you mean: Mathf.FloorToInt(Mathf.Min(gridSizeX * percentX, gridSizeX - 1))
@mr_donutz
@mr_donutz 4 жыл бұрын
just finished watching this tutorial, now gotta do it 99 more times for me to get it
@TroyMakesGames
@TroyMakesGames 2 жыл бұрын
At least you'll get a skill cape
@Ensiferum888
@Ensiferum888 9 жыл бұрын
Amazing tutorial, I'm using Aron Granberg's pathfinding since I couldn't implement it myself. Your explainations are extremely easy to understand. Great work!
@naipeadicto
@naipeadicto 9 жыл бұрын
Thanks!!!!!!! Incredible explanation! I was struggling setting the grid for my project, but I followed along and it turned out really simple and easy. now to part 3...
@FranciscoAmorim
@FranciscoAmorim 7 жыл бұрын
19:30 if you round down a percentage multiplied by a grid-1 you can end with a target one node away from your actual current node. Take x = 14.4 for example: (14.4 + 30 / 2) / 30 = 0.98 x = round(29 * 0.98) = round(28.42) = 28, so you end up at node 28. But if your x = 14.4 you are between x=14 and x=15, so you actually are at the far right node (29) You should not round and subtract one, you should floor without subtracting: x = floor(30*0.98) = floor(29.4) = 29 edit: you also need to clamp before floor: int x = Mathf.FloorToInt(Mathf.Clamp((gridSizeX) * percentX, 0, gridSizeX - 1)); o/
@zoetechandme
@zoetechandme 3 жыл бұрын
You should also remove these lines> percentX = Mathf.Clamp01(percentX); percentY = Mathf.Clamp01(percentY); Becouse otherwise the bottom Y node is always one above from the current node. This is my whole function: public Node NodeFromWorldPoint(Vector3 worldPosition) { float percentX = (worldPosition.x + gridWorldSize.x / 2) / gridWorldSize.x; float percentY = (worldPosition.y + gridWorldSize.y / 2) / gridWorldSize.y; int x = Mathf.FloorToInt(Mathf.Clamp((gridSizeX) * percentX, 0, gridSizeX - 1)); int y = Mathf.RoundToInt((gridSizeY) * percentY) +1; return grid[x, y]; }
@DancingManson
@DancingManson 3 жыл бұрын
@@zoetechandme Can you please elaborate this little bit more. Why do you need to add +1 to int y?
@umarfaroukabdulmutallab4451
@umarfaroukabdulmutallab4451 2 жыл бұрын
o/
@OlCowic
@OlCowic Жыл бұрын
This!
@camo_man
@camo_man Жыл бұрын
THANK U
@damien5266
@damien5266 8 жыл бұрын
You're an amazing programmer. Thanks for the videos.
@MrSquishedsquashed
@MrSquishedsquashed 9 жыл бұрын
Really great tutorial! Quick, to the point and clear. Thanks!
@PatrickWilliamsphd
@PatrickWilliamsphd 6 жыл бұрын
I have watched this and Part 1 and am super excited to try this stuff out. I'll be able to quickly create some fun games for my kids with this AI. Keep up the good work friend.
@MACHINEBUILDER
@MACHINEBUILDER 3 жыл бұрын
I saw this video in my recommended, and I've already watched it twice, but I clicked on it again just to listen to your voice lol
@bejoscha
@bejoscha 4 жыл бұрын
Lovely pace for learning stuff - including mistakes, which are a natural part of the coding experience. I’m glad you are not editing them out.
@10chaos1
@10chaos1 9 жыл бұрын
thank you very much for this Sebastian i now understand what i need to do to make a placement grid for my citybuilder game project
@JakeDownsWuzHere
@JakeDownsWuzHere 8 жыл бұрын
worked perfectly for me. really enjoying this series. :D thanks for sharing it
@AA-vf4fv
@AA-vf4fv 7 жыл бұрын
Thanks for the great Tutorial. It helped me very much. Also good explanation and easy to follow.
@burhanuddin9047
@burhanuddin9047 3 жыл бұрын
Thanks a lot. You are the best 😊 teacher. Explained everything in details and your voice have magic, can hear all the day without feel bored. thanks a lot again. 😇😊
@lamdasoftworks1165
@lamdasoftworks1165 6 жыл бұрын
I'd love to see an update on this, using unity's new Tilemap Grid system.
@bwegrzyn
@bwegrzyn 3 жыл бұрын
I'm trying to implement this in Java and it works fine. I only had problem with percentX and percentY, wich were returning 5X bigger value than they should, but I fixed it. Thanks for great tutorial!
@jessejones6756
@jessejones6756 4 жыл бұрын
No idea what you're talking about but I'm still interested.
@tumankito7776
@tumankito7776 3 жыл бұрын
I am a big fan of you! Great way to explain the logic of your code, thanx for the amazing tutorial.
@jasperh6618
@jasperh6618 9 жыл бұрын
I absolutely love this ^^ such a clear explanation :)
@web_tutorials_for_beginners
@web_tutorials_for_beginners 9 жыл бұрын
Sebastian Lague More, and more videos please, you are a great tutor!!! More videos about anything! In every video I learn something new.
@SebastianLague
@SebastianLague 9 жыл бұрын
Thank you Marcell :)
@dennischan2263
@dennischan2263 6 жыл бұрын
excellent tutorial, thank you very much dude, you save my FYP and my life
@yuuryu2394
@yuuryu2394 7 жыл бұрын
exactly what i was looking for, thanks a lot! :D
@tshichan
@tshichan 4 жыл бұрын
I wish the youtube has another LIKE button !! thank you Sebastian for this piece of magic code :)
@moduntilitbreaks
@moduntilitbreaks 4 жыл бұрын
This guy is the reason i requested .1x playing speed from KZbin.
@Undead2k
@Undead2k 6 жыл бұрын
Thanks for making this tutorial and for also adding the source files for the 2D project somewhere in the comments (as the video is for 3D). I am still learning c# and unity and now trying to learn A* pathfinding. I am finding this really useful and educational.
@dead2gamer
@dead2gamer Жыл бұрын
Hey can you link me up with the code for 2D. I'm working with this and trying to figure out how to check for collisions on 2D
@MrNintendeion
@MrNintendeion 3 жыл бұрын
Omg I know I'm a bit late so you may well not see this comment but this tutorial dude wow. I'm trying to implement A* into an Xcom style strategy game and after hours of trying to follow another KZbinr (I won't name names but god it was infuriating), this tutorial is just what I needed :) I've followed this all the way through and feel so much better about A* now, you're a great programmer mate thanks so much.
@Bluzora.
@Bluzora. 9 жыл бұрын
Useful! Love it! Keep it going man! :D
@michaelveloso
@michaelveloso 8 жыл бұрын
good clear instructions. thanks
@MangaPianet
@MangaPianet 2 жыл бұрын
Talk about A(*) programmers! Great video and great code, I love all your videos!
@pixeldust8362
@pixeldust8362 4 жыл бұрын
I came here from this guy named Daniel... he kind of just reuploaded your tutorial with his following your tutorial... he did NOT fix the "that's y it's meant to be z" for the percent value. I've been stuck for a week. Lol.
@zhaoxuefei3829
@zhaoxuefei3829 2 жыл бұрын
omg, what a amazing video for a star, thank you very much
@TheCJBaldwin
@TheCJBaldwin 8 жыл бұрын
Great tutorial - many thanks
@DriitzzCabal
@DriitzzCabal 6 жыл бұрын
I would like to see how you would go about having an Enemy AI that jumps up and down platform to chase the player , in a 2D SideScroller platformer, Which route would you pick ? A* pathfinder , Raycast , Grid base ,MeshBase. Possibly also giving your opinion on difference between them with Pros and Cons.
@sallycleverdoggo700
@sallycleverdoggo700 2 жыл бұрын
This is so good! Thank you!
@pablokalemba2924
@pablokalemba2924 5 жыл бұрын
Thanks !! you saved my proyect
@yagohenriquepereira3367
@yagohenriquepereira3367 8 жыл бұрын
amazing tutorial! Thanks
@badrballish9328
@badrballish9328 3 жыл бұрын
Great tutorial thank you very much.
@Robsfund
@Robsfund 8 жыл бұрын
Hey, great video! Quick question, if I want a grid node for a 3d terrain, should I just raycast down and create each node at the hit point, is it that simple?
@MrDavidCollins
@MrDavidCollins 3 жыл бұрын
Just implemented this for my infinite world map! I love GMS2's new class/object programming
@kevinmolinari8953
@kevinmolinari8953 7 ай бұрын
what?... how? seriously, im lost how do u do it for an infinite map
@javiermurarios3960
@javiermurarios3960 8 жыл бұрын
very wonderfull tutorials man, im enjoying so much your tutorials. And i want to add something very little, i dont like that NodeFromWorldPoint get the node to the right or bottom of the capsule so i modified the percent so they are calculated from the center of the capsule, but i dont know if the modification i did its really working on any case, here is my modification: percentX = (worldPosition.x + gridWorldSize.x/2 + nodeRadius) / gridWorldSize.x; percentY = (worldPosition.z + gridWorldSize.x/2 + nodeRadius)/ gridWorldSize.y; pd: forget it, it doesnt work, i was testing it just for the top right, the other sides doesnt work. pd2: well i think now works, just to make more precise the transition between nodes: public Node NodeFromWorldPoint(Vector3 worldPosition) { float percentX = (worldPosition.x + gridWorldSize.x/2) / gridWorldSize.x; float percentY = (worldPosition.z + gridWorldSize.y/2) / gridWorldSize.y; percentX = Mathf.Clamp01(percentX); percentY = Mathf.Clamp01(percentY); int x = Mathf.RoundToInt((gridSizeX-1) * percentX); int y = Mathf.RoundToInt((gridSizeY-1) * percentY); //here start my added modification if (grid [x, y].worldPosition.x + nodeRadius < worldPosition.x && x < gridSizeX - 1 && x > 0) x++; else if (grid [x, y].worldPosition.x - nodeRadius > worldPosition.x && x < gridSizeX - 1 && x > 0) x--; if (grid [x, y].worldPosition.z + nodeRadius < worldPosition.z && y < gridSizeY - 1 && y > 0) y++; else if(grid [x, y].worldPosition.z - nodeRadius > worldPosition.z && y < gridSizeY - 1 && y > 0) y--; return grid[x,y]; } this should be easy for you but since i'm new with unity i wanted to see if im doing it right.
@aidansoles5113
@aidansoles5113 9 жыл бұрын
You are a boss at debugging....
@klevialushi571
@klevialushi571 2 жыл бұрын
its an old video but gotta love the fact that you got stockfish there
@riteshrobotics9713
@riteshrobotics9713 2 жыл бұрын
A* Life Saver Was a really good video!
@gadgetboyplaysmc
@gadgetboyplaysmc 4 жыл бұрын
There's another way to do 17:17 on the NodeFromWorldPoint function. Which is to just Vector3.InverseLerp(-gridPosition*.5,gridPosition*.5,worldPosition.x) It's automatically clamped to 0 and 1 so no need to do Mathf.Clamp or whatever: Mathf.InverseLerp(-gridWorldSize.x*.5f,gridWorldSize.x*.5f, worldPosition.x); Mathf.InverseLerp(-gridWorldSize.z*.5f,gridWorldSize.y*.5f, worldPosition.z); Remember, gridWorldSize and worldPosition are 1:1 proportion. Little definition of Inverse Lerp: InverseLerp(min,max,t) What InverseLerp does is that it returns a float value that converts value t into a value between 0,1. Kinda like Lerp except t is a value you pass in that is between 0 and 1 and returns a float value that is between min and max.
@MoloSolo
@MoloSolo 8 жыл бұрын
Congratulations, I'm really enjoying your tutorials! Just one question. Don't you think it could be better to define variables "worldPoint" and "walkable" (lines 27 and 28) outside of the "for" instructions and assign the new value inside? I think it's faster to define these variables just one time instead of creating and destructing them in each loop. What do you think?
@BlockerofDoom
@BlockerofDoom 7 жыл бұрын
Awesome video, one problem that I encountered while testing this code is that when you pass the player position parameter to NodeFromWorldPoint you have to convert coordinates to local relative to grid object with Transform.InverseTransformPoint otherwise if your grid is not centered on 0,0,0 then it will not work :)
@Tevan1n
@Tevan1n 3 жыл бұрын
Hey there, I know it's 3 years late, but how would you go about doing this? Could you clarify? Thanks.
@canfly8385
@canfly8385 6 жыл бұрын
thanks man, youre great.
@jdelaay025
@jdelaay025 8 жыл бұрын
fantastic tutorial Sebastian!! I have one issue. The playerNode will not update or show as a different color. I even continued on I even continued on to the next tutorial for pathfinding to see if the old code would correct itself and it did not. I changed the zed and y coordinates and everything but it would work on either the x or y plane. So that means no path finding. It does work for the layer mask but none of the update type of functionality. Just the stuff that's on the startup section what do you suggest
@HendrioLuis
@HendrioLuis 9 жыл бұрын
Great tutorial :)
@sandichhuu
@sandichhuu 7 жыл бұрын
Great videos
@davidpike5959
@davidpike5959 6 жыл бұрын
wow, copying this guy makes me feel clever :O
@StarkTech47
@StarkTech47 6 жыл бұрын
Hi very good tutorial and very interesting. When I was whatching this I asked me if is it possible to adatpe this path finding to a shpere ? If it is not, do you have any idea to help me ?
@RetroEcoChicken
@RetroEcoChicken 4 жыл бұрын
you can use this with his cavesystem if you diable the node script then enable it after runtime when the mesh and collision has been generated.
@Krebzonide
@Krebzonide 6 жыл бұрын
How would you change this to make it work with 2d sprites instead of cubes? So far my best idea is to hide cubes behind the sprites which has worked but seems like it might cause lag with lots of obstacles. Edit: Looking over it it seems that it is the boxes collision that causes the detection so I just need some way to add collision to sprites.
@L0932
@L0932 9 жыл бұрын
Sebastian Lague If I wanted to make the cyan colored detection cube for the player to work properly, does the plane have to be centered at 0,0,0? I've tested this out and that seems to be the case. What's a good solution to have the player detection working properly for planes positioned at any world position? Thanks in advance.
@romainchow5706
@romainchow5706 6 жыл бұрын
what does the Node[,] variable do in Grid? It's not working for me, do I have to attach the node script?
@RoutineJustice
@RoutineJustice 9 жыл бұрын
I was JUST wondering how I was going to do the AI for the top down shooter. I've had some exposure to A* before but never in the context of actually doing it. Sebastian: I love you.
@windowsxseven
@windowsxseven 3 жыл бұрын
lmao gay
@Phagocytosis
@Phagocytosis 2 жыл бұрын
​@@windowsxseven I love you
@windowsxseven
@windowsxseven 2 жыл бұрын
@@Phagocytosis 💝💝💘💋💋💌💓💕💞❤️‍🔥💟💚💙💜😘😘😙🥰💕💗💖
@catanator123654
@catanator123654 7 жыл бұрын
So I got all the code right but it just wouldn't work and after a half hour of checking over the code turns out I misspelled "position" 😑
@Villfuk02
@Villfuk02 7 жыл бұрын
that's 40% of being programmer - fixing simple mistakes ¯\_(ツ)_/¯
@elektro36
@elektro36 5 жыл бұрын
A CLASSIC
@chappie3642
@chappie3642 4 жыл бұрын
How did you not see that on the error log lmao
@alexanderrupp1209
@alexanderrupp1209 3 жыл бұрын
That’s a mood
@daksheshgupta7045
@daksheshgupta7045 3 жыл бұрын
get a linter
@FeuerfallFan
@FeuerfallFan 7 жыл бұрын
if you have an inaccurate position from the NodeToWorldPoint, make sure your GameObjects position with the Grid Script is set to Vector3(0,0,0)
@worempie
@worempie 7 жыл бұрын
A little late and don't know if this has been posted already or not, but currently you don't use the unwalkableMask. If you have for example other gameobjects with a collider, they will also be added to the non-walkable grid. To fix this you have to add the layer mask to line 28: bool walkable = !(Physics.CheckSphere(worldPoint, nodeRadius, unwalkableMask)); Also to update the grid just run the CreatGrid(), for example by pressing the N button: if (Input.GetKeyDown(KeyCode.N)) { CreateGrid(); } or from a different script (don't forget to make CreateGrid() public: if (Input.GetKeyDown(KeyCode.N)) { GameObject.Find("A*").GetComponent().CreateGrid(); }
@theearthisdonut-shaped2142
@theearthisdonut-shaped2142 9 жыл бұрын
How did you configure the lighting and skybox like that?
@leddy_
@leddy_ 9 жыл бұрын
I've been using "Sublime Text 2" in Unity for a little while now, mostly because I love its Ctrl+D function. When you mentioned the replace x with y using Cmd+R at 8:32, is that a plugin? I do notice you are using iOS, while I am on Windows, but I tried using Ctrl, the Windows button, Alt, Shift, and then went on Google to try and look it up. I can't find anything on it. This might be a stupid question with an obvious answer, but I'm just very confused right now and would love to know how you did that. :P
@josepacio7579
@josepacio7579 8 жыл бұрын
I've been trying to figure this out for a while now, but how could I modify this to make each node a bit more rectangular, as in increase the width of each node?
@mohamedsalbi2759
@mohamedsalbi2759 3 жыл бұрын
Best channel ever
@JFkingW
@JFkingW 9 жыл бұрын
Good Tutorial! Do you know a way how to detect touch gestures?
@batomow
@batomow 7 жыл бұрын
I know this might be a little bit off topic, but have you considered doing a GOAP AI tutorial? Since this sort of pathfinding is popularly implemented with GOAPs, i figured it could be an interesting follow up. Also, keep up the good work :)
@spectreshadow9901
@spectreshadow9901 8 жыл бұрын
hi Sebastian, i like your videos and thank you for uploading and sharing them, i am having problems with the grid script. i am writing the code as you show but i keep getting build errors and am stuck on video 2 placing the script on to A* empty. please can you help? i use windows 7 as i cannot afford a mac. thank you in advance
@alisontaylor4589
@alisontaylor4589 8 жыл бұрын
is it possible to use this in a game in unity where your scene is so smalll that your node points to world points need to get small floats/doubles? I'm trying to use this in a game but sometimes my enemies go to spots they shouldn't be able to and get stuck, i think its something with the conversion but not sure.
@marielauredebeaune1780
@marielauredebeaune1780 Жыл бұрын
thanks for this video how can I do for only make a line renderer betwen a few cubes in taking the shortest path?
@mexico9500
@mexico9500 7 жыл бұрын
Love the video, please do audio books - your voice is great!
@Random0scar
@Random0scar 6 жыл бұрын
Does the ondrawgizmos only update once? Because I have a game where you will be able to add and remove blocks and they dont turn red/white if I do.
@3personal5me8
@3personal5me8 2 жыл бұрын
Me, about to go to bed because I work tomorrow: "Well, guess I'm watching this whole series first".
@naderabdullah8569
@naderabdullah8569 8 жыл бұрын
How do you make those words highlighted in white in Solarized Dark?
@sits
@sits 8 жыл бұрын
We should also take node radius and our A* object position into account when getting node from world point or the results will be pretty inaccurate. Here's what I ended up with: float percentX = (worldPosition.x - transform.position.x) / gridWorldSize.x + 0.5f - (nodeRadius / gridWorldSize.x); float percentY = (worldPosition.z - transform.position.z) / gridWorldSize.y + 0.5f - (nodeRadius / gridWorldSize.y);
@ukaszw7924
@ukaszw7924 8 жыл бұрын
+Alexander Sorokin Thanks!
@ashleytwo
@ashleytwo 8 жыл бұрын
+Alexander Sorokin I think I'm having this problem. When I was following along and testing and put it at 0,0,0 it was all fine. Now that I actually want to implement it in my game as soon as it pathfinds it's trying to go somewhere weird. I think its the NodeFromWorldPoint method that's doing it but can't figure out how to fix it. Your reply seems to suggest there should be some code. Mind posting it again as I can't see anything and I'm hoping you have the answer! Thanks :)
@sits
@sits 8 жыл бұрын
Ashley Jones dunno why you don't see it, I am still seeing it in my reply. Anyway, here you go: gist.github.com/alsorokin/2550976f89b5649314a4
@FeuerfallFan
@FeuerfallFan 7 жыл бұрын
Helped me, thank you very much! :)
@TheTwyker
@TheTwyker 7 жыл бұрын
this is the most important comment on youtube I've ever read! UP YOU GO, SIR! WITHOUT THIS, YOU CAN'T USE IT IN YOUR GAME, meaning: you can't move the grid.
@wakka2100
@wakka2100 7 жыл бұрын
i follow your tutorial i got an error at gizmos says null reference and the grid only draw cube to right not all the places any way to fix this ?
@amanmahendroo1784
@amanmahendroo1784 4 жыл бұрын
Awesome videos! But could you please increase the font size of your code? That would be great
@dexyuzs
@dexyuzs 8 жыл бұрын
Hi Sebastian, nice tut! The 'NodeFromWorldPoint' function works fine for me when the player is near the (0, 0) point (the center of the map, we can say). But it gives me unaccurate values if I put the player far from that point. Any ideas about what's happening? Thank you!
@moeayyad8228
@moeayyad8228 5 жыл бұрын
Is it weird that I reply to a 3-year-old comment? Were you able to solve this? I kinda know where the problem is; if you're in a position that is larger than the grid world size (say your world size is set to 20 and you're at position 70), you're technically out of bounds, even though you're inside the grid, and that's because the division result will be larger than 1 which would then be clamped to 1 which is at the border of the grid. So we need some kinda offset from the origin, but so far all my attempts have failed :(
@moeayyad8228
@moeayyad8228 5 жыл бұрын
I've actually just solved the problem. As I mentioned above, the problem was with the offset. I was trying to offset everything from the origin, but the solution was to actually pretend we've never left the origin. To do that, I subtracted the player's position with the object's position (so if the player is at 75,0 and the enemy is at 70,0 --> We can treat it as if the enemy is at the origin and the player is at 5,0), this way the function makes sense and resulting value would always be
@PauloHenrique-em2ly
@PauloHenrique-em2ly 3 жыл бұрын
Just a question, if i make the gridWorldSize with diferent values, like (x=40, 15) the variable WorldBottomLeft still get the correct value?
@videomasters2468
@videomasters2468 9 жыл бұрын
if possible i would really like to see a tutorial/tutorial series on procedural level generation :)
@SebastianLague
@SebastianLague 9 жыл бұрын
Yeah that'd be fun :) Do you have something particular in mind? I could easily do some sort of cool cave generation using using cellular automata..
@videomasters2468
@videomasters2468 9 жыл бұрын
Sebastian Lague Yeah, either your suggested cave generation or some kind of race track, which would be of greater interest to you ?
@JoshD22
@JoshD22 9 жыл бұрын
Another great tutorial Sebastian! Procedural generation sounds like a great idea! I would also like to suggest procedural voxel terrain in Unity, maybe block type worlds like Minecraft or smooth voxel terrains by using something like marching cubes or even better Dual Contouring, which allows you to have sharp features for buiulding but the smoothness that you want for the ground.
@trevor7066
@trevor7066 9 жыл бұрын
Sebastian Lague I think something along the lines of Terraria style map generation would be extremely useful.
@BrainRobo
@BrainRobo 9 жыл бұрын
Sebastian Lague Also, if possible random planet generation, using spheres as the planet for space exploration, would be very intriguing.
@DerXavia
@DerXavia 7 жыл бұрын
I wonder why you use the sphere check instead of a boxcheck, isn't that more efficient?
@annaleonid6095
@annaleonid6095 8 жыл бұрын
Hey - you are amazing! I love your teaching style! Thank you for these videos. I just wanted to ask - does the grid know how to detect sprites? I have no trouble getting the grid set up the way you have it, and it works fine with cubes as long as they're under the layer "unwalkable", or with newly imported quads etc. But not sprites, it seems. Do you have any advice? Is there something about the sprite renderer that acts differently than a mesh renderer? Thanks again!
@annaleonid6095
@annaleonid6095 8 жыл бұрын
Perhaps it's something to do with the "bool walkable = !(Physics.CheckSphere (worldPoint,nodeRadius,unwalkablemask)); ? Because sprites are 2d, does it have to be a different physics check? that's my guess anyway.
@_graiderz2462
@_graiderz2462 8 жыл бұрын
+Anna Leonid Yup yup. For 2D, Change, bool walkable = !(Physics.CheckSphere (worldPoint,nodeRadius,unwalkablemask)); to bool walkable = !(Physics2D.OverlapCircle(worldPoint, nodeRadius, unwalkableMask)); After this, it will still not work because, the sprite have no collider to detect collision (Physics2D.OverlapCircle) Therefore, add a 2D collider to the sprite. Worked on mine.
@annaleonid6095
@annaleonid6095 8 жыл бұрын
+Muhd Amirul Thanks!! That totally works!! One more question. How would I set walkable so that it can detect both sprites and 3d objects? bool walkable = !(Physics2D.OverlapCircle(worldPoint, nodeRadius, unwalkableMask)) || !(Physics.CheckSphere (worldPoint, nodeRadius, unwalkableMask)); Am I missing some parentheses? I'm unable to get the grid to detect both.
@_graiderz2462
@_graiderz2462 8 жыл бұрын
+Anna Leonid Yo yo, Sorry for late reply. I was addicted to a specific game and yeah... I apologize, as this time, I am unable to explain why the following code work. Change, bool walkable = !(Physics2D.OverlapCircle(worldPoint, nodeRadius, unwalkableMask)) || !(Physics.CheckSphere (worldPoint, nodeRadius, unwalkableMask)); to bool walkable = !( (Physics2D.OverlapCircle(worldPoint, nodeRadius, unwalkableMask)) || (Physics.CheckSphere(worldPoint, nodeRadius, unwalkableMask)) ); It would seems that it has something to do with the ''!''. If it still doesnt detect the 3D object, make sure that the 3D object is touching the Grid. If it still doesnt work, then all the best. Im not sure if the new code would affect the pathfinding, because I already ditch my plan of using this tutorial because it doesnt provide me with smooth pathfinding, and dynamic pathfinding.
@IFrozenFireI
@IFrozenFireI 8 жыл бұрын
"dynamic pathfinding"? Dude, for it to be "dynamic", you should just call the appropriate code in an update function.
@tr25ny
@tr25ny 7 жыл бұрын
trying to get the world bottom left based on the z rotation. so that if my grid object is rotated on a 45 degree angle the world bottom left will be aligned diagonally is this possible. (I'm using it in a 2d space)
@antonpolchenko6391
@antonpolchenko6391 7 жыл бұрын
You realy good, how long you been working with C# and Unity?
@mahmoueco1200
@mahmoueco1200 4 жыл бұрын
wow,just wow dude u r amazing where r u from !!! from land of genuis
@alexandergilbert7572
@alexandergilbert7572 9 жыл бұрын
It might be a fun little project to get A* path finding to work on your spherical world.
@arandomlizard3411
@arandomlizard3411 5 жыл бұрын
"fun" might not be the best word to describe it.
@azrailnone
@azrailnone 3 жыл бұрын
Any suggestions for me to find the best way to learn C# like that??? have been struggling for a while now, quite a complex lang.
@JonathanZigler
@JonathanZigler 9 жыл бұрын
Very nice
@Ben274722
@Ben274722 8 жыл бұрын
Hey Sebastian, great Video !!! But I have a question about the Node-Constructor in the Node class. I am a starter-programmer so forgive me any stupidity. Here is my Question : Why didn't you create the Node-Constructor in the grid-script and would this be possible too ? BR, Ben.
@marypearldegamo6371
@marypearldegamo6371 6 жыл бұрын
hey, how can i extend the nodes to another floor ,i want to find path from 1st floor to 2nd floor?
@ashersmith3654
@ashersmith3654 4 жыл бұрын
Thanks sm bro
@sergiopradabarrios2243
@sergiopradabarrios2243 8 жыл бұрын
Thank you
@sachacerf6513
@sachacerf6513 7 жыл бұрын
Hi sebastian. Ive got a problem with the playerNode : its not at the player position, but it moves correctly when im moving the player around. I think its a problem with the NodeFromPosition method, but i dont see any problems. Any idea? Edit : Ok, the Astar GameObject had to be at (0,0,0)
@devlog98
@devlog98 6 жыл бұрын
Hello there! I know this video is quite old, but I'd like to ask something... for some unknown reason, the nodes that are at the corners of my objects don't turn red, unless I change the value of the node size... it's weird because I can clearly see the object tresspassing the node's limits... well, thanks in advance, and keep up with the great work!
@anma7424
@anma7424 4 жыл бұрын
thank you very mutch
@ALightInTheAutumnRain
@ALightInTheAutumnRain 6 жыл бұрын
Could someone explain why all the nodes turn cyan if the Node.cs inherits from Monodevelop?
@luckylove72
@luckylove72 4 жыл бұрын
Can you do a full ECS implementation !
@Omran_90
@Omran_90 5 жыл бұрын
does it have to be square nodes? what i have diagonal pathways like slopes. I'm talking about a 2D platformer game slopes.
@thebaconbreadful
@thebaconbreadful 5 жыл бұрын
Hey! Thanks for this tutorial! It was pretty helpful but now I struggle to implement this for a round gameworld... Do you have any tipps for me?
@Victor-oo4ux
@Victor-oo4ux 5 жыл бұрын
Round as in a planet? Dont use squares!
@chrisgengr
@chrisgengr 8 жыл бұрын
Hey Sebastian, I was wondering what the equivalent of creating a plane and, using gizmos to visually display the walkable and unwalkable regions of the world would be for a 2d project? Furthermore, What is the equivalent of the Physics.CheckSphere method in a 2d environment? At the moment I am currently using colliders, and I was hoping that there is a better solution in existence. Thanks!
@PvPNetwork
@PvPNetwork 5 жыл бұрын
Phyiscs2D.OverlapCircle works. 3 years late answer, but maybe someone else in the future will find it useful.
@gustavoguaresi8698
@gustavoguaresi8698 2 жыл бұрын
@@PvPNetwork yeah, thanks. 2 years late, but still... haha
A* Pathfinding (E03: algorithm implementation)
24:11
Sebastian Lague
Рет қаралды 444 М.
Why 3D Printing Buildings Leads to Problems
15:44
Stewart Hicks
Рет қаралды 220 М.
Pokey pokey 🤣🥰❤️ #demariki
00:26
Demariki
Рет қаралды 8 МЛН
Sprinting with More and More Money
00:29
MrBeast
Рет қаралды 73 МЛН
Кәріс өшін алды...| Synyptas 3 | 10 серия
24:51
Pathfinding - Understanding A* (A star)
12:52
Tarodev
Рет қаралды 113 М.
A Comparison of Pathfinding Algorithms
7:54
John Song
Рет қаралды 704 М.
Coding Adventure: Chess
29:22
Sebastian Lague
Рет қаралды 3,7 МЛН
Visualizing Pathfinding Algorithms
10:03
CodeNoodles
Рет қаралды 145 М.
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,4 МЛН
The hidden beauty of the A* algorithm
19:22
polylog
Рет қаралды 824 М.
A* Pathfinding Algorithm (Coding Challenge 51 - Part 1)
48:42
The Coding Train
Рет қаралды 3,3 МЛН
Pathfinding in games. How to do it for 30k entities.
14:21
Songs of Syx Official
Рет қаралды 25 М.
Unity3D Particle Sun Tutorial
18:17
mrwasd
Рет қаралды 82 М.
Smart girl 😱🤢 LeoNata family #shorts
0:23
LeoNata Family
Рет қаралды 2,8 МЛН
ФОТОШОП СВОИМИ РУКАМИ (@photoscapesbyclare - IG)
0:30
В ТРЕНДЕ
Рет қаралды 18 МЛН
Ele Comeu a TERRA da Planta😱 #shorts
0:59
Lucan Pevidor
Рет қаралды 20 МЛН
Лучший Minecraft box ASMR
0:27
Mikha Zen
Рет қаралды 1,2 МЛН
Необычный Способ ОМОЛОЖЕНИЯ😕
0:32
ИССЛЕДОВАТЕЛЬ
Рет қаралды 2,9 МЛН
Which water gun do you want?
0:33
toys AS
Рет қаралды 3,3 МЛН