Custom Movement on a Grid and Path-Finding: Unity 3D Tutorial
Druidstone Review: • Druidstone: Secret of ...
Files for this tutorial: / randomartattack
Twitter: / randomartattack
Facebook: / randomartattack
Druidstone Review: • Druidstone: Secret of ...
Files for this tutorial: / randomartattack
Twitter: / randomartattack
Facebook: / randomartattack
Пікірлер: 183
thanks for this for anyone confused (Like I was) at 7:35 he's saying to create an empty(1), then add the GridStat script to that empty(1). Then, create a new empty(2), and add the GridBehavior script to that empty(2). Then, in the GridBehavior script within the empty(2), drag the empty(1) that has the GridStat component. The first empty(1) can in fact be any game object, so if you want to see the grid then make it something with a model like a sphere.
@nwm83
2 жыл бұрын
Thank you for clarifying!
@Shemwow
2 жыл бұрын
very helpful. thank you, good sir.
For anyone interested, the pathfinding algorithm he described at the beginning is called Wavefront
@RandomArtAttack
4 жыл бұрын
I did not know this, thank you!
@LucasAlfare
3 жыл бұрын
What the difference to A* in pathfinding?
@jikosauce
Жыл бұрын
Thanks your a boa
@robertfletcher8964
3 ай бұрын
There are great pathfinding videos here. kzread.info/dash/bejne/Yp2cxcuGe8_JgJs.html
This tutorial and the information in it is fantastic, but if I'm honest, the way you blitzed through the video was really chaotic. Coding so quickly and leaving errors here and there which you then came back to and fix while in the middle of another point made it hard to concentrate and focus on what you were saying. Not commenting the code as you went at all to allow the viewer to follow along easier (particular when talking about directions because it was just a lot of numbers being repeated over and over) also made it hard to digest. Just my two cents, but thank you otherwise for a great video and for providing this information!
@revarddez4817
4 жыл бұрын
I agree with Conor, it is an excellent tutorial but from the POV of a beginner it could be extremely hard to follow and understand whats going on. There is also the last part where you have the ball moving which you use to test your array. It kinda hit me that I wanted to test my code to see if I made any mistakes. But you didn't include how you integrated it with the moving object.
One of only a couple videos I could find on this topic, and this is the best! Well done!
You really didn't include how to actually move an object on this grid that we have spent almost 30 minutes working on? You just threw in your own AI script at the end without explaining how it interacts with the grid system???
@deepakkalyani4935
3 жыл бұрын
yes bro i facing same issue here.
way over my head. I can't wait to come back to this later when I know enough to understand what you're saying.
This video was a great help. The code works and can be optimized further as pointed out by others. Creator flew by his code entry and corrections so I needed to rewatch several times but all's good. The UI code wasn't shown but I only wanted to adopt the pathfinding modules. The important thing is the grid resolution be setup exactly 1 unit square to work well with the codes. x-axis represents column traversal while y-axis is row. 0,0 indicates the left-bottom tile. Given any x,y tile coordinate, x-1,y would be the adjacent left tile, x,y+1 the adjacent top tile and so on. The gist of the pathfinding process is first to walk the entire tileset and set the individual tile "visited" values. Start tile is value 0, adjacent tiles (top, bottom,left, right) are 1 and so on fanning outwards. Second is to decide on an End tile, look for it's "visited" value and walk the tiles to pick those with decrementing "visited" values all the way back to the Start tile. A (optional) visual improvement is to apply vector distance computation to choose the best tile from a selection of tiles with the same "visited" value, which is done in "FindClosest" function. Otherwise the shortest path could be a long line of horizontal and vertical movements, instead of a more pleasing zig-zag manner.
The most interesting part: Grid AI script, is not demonstrated.
@mobeenahmed361
7 ай бұрын
Is it resolved, if yes, please share..!
Ahh.. this exploded my brain cells and created new ones thanks bro
The code at the end isn't the same as what the guide went through. Multiple variables are added right at the end with no explanation. What a waste of time.
@Programm4r
4 жыл бұрын
Yeah, there were a few unused instantiations in this tutorial - specifically in the SetDistance() method. For instance, he has a testArray that is not doing anything at all. lol
when I run the "GridBehavior" script, it does not go through either of the for loops. When i call the function in the if statement, it skips both loops and will do any other statements after that in the conditional. Any help with this would be awesome! Thank you!
Excuse me but how do you draw the maximum displacement area with a bright line? Or just the name to look up on the internet for information on this?
Thats awesome! quick question, what if it's a tie to the shortest distance?
How can I make the grid work for 3d scenes with more than 1 floor that can have multiple connections between floors?
I'm having a spot of trouble trying to figure out how best to move an object to the path defined. I'm not sure how to go through items in a list and have an object move to each in order. Any advice/feedback?
@LordVonLeo
4 жыл бұрын
Yeah I have the same problem. Would love a tutorial on that
You lose me right in the beginning. I followed your code to the tee but I am only getting a single cube (I chose a Cube as my "Grid Object"). Taking a look again, the icon next to your prefab in Inspector doesnt look like mines. Is that a special kind of prefab ?
Would it be possible to have a tutorial of how you link that Sphere at the end to the grid? I'm wondring how to use that grid/generated path with an object... Also it is clear that at the end of this video, the code has been modified since there's an error generated with the removal of some grid objects..
@mobeenahmed361
7 ай бұрын
did you get it..?
@viscarious1
28 күн бұрын
@@mobeenahmed361 I guess you got nothing? I was hopefull i finaly found a solution to my game issue.
Is there a way to do this but with isometric tiles in 2D?
But this doesnt move diagonally like in the game as u showed, another thing, how good of performance it would have to check while using the mouse and draw the lines of the path? but great work. I think can also be integrated with navmesh with some tinkering in the scene.
Is there a chance you could also do it with Unity Tilemaps please ?
I am sure people have said this already, but using the variable name "x" and "y" when iterating through your for loop when generating the grid instead of "i" and "j" will help you avoid confusion.
Kind of falls short when you didn't go over the Grid AI script. I know this is an old video, but a follow up on how to do the player movement on the sphere would be nice.
@loganou9746
11 ай бұрын
YES ! This part is really really poorly covered. geez
is there a way to make some of the grid unaccessible, until a boolean condition is met, so some surfaces can be accessed after so condition is met?
@RandomArtAttack
4 жыл бұрын
Sorry for the late response. You could always force the number on the grid via code by setting it to -1 for example. When the boolean is met, simply set it to 0 or whatever number scheme you use.
i got error on FindClosest function where its says argumentout of range return list[indexNumber]; is the error code
Hey! I have tried this tutorial and made it to the end. I fixed all the little errors, my mistakes, however when i press play and click the findDistance button it creates the path but doesn't move? i've tried pressing it twice but the bigger ball (player or whatever) doesn't do anything? how do i fix it. Is it because i dont have the move and moveSpeed variables u never explained or are they unnessasary?
@sebzanardo
4 жыл бұрын
If anyone got i working could they please send it to me :( i've tried for so long to get it working. even re-watched the entire video to make sure i did everything right
Can you share how to make the arrow like yours?
You could add a check for if you are adding step at the target location, then you can backtrack, looking for the next lowest number in the sequence, whilst adding to the path array
it dind work if i remove one part in the grid, ithink the problem is in the gridArray or in the TestFourDirections?! how can i fix it?
Got any videos for hex based grid movement?
I am new to unity: isn't getcomponent expensive? Seems like doing it every test direction seems very wasteful. would it be better to maybe store a reference to this all the gridstat components in an array?
@phleticgaming3981
4 жыл бұрын
actually that is true. but honestly Get Component wont affect much to the game unless there are many instances of objects referring to it at one time
What is GridStats with an S? It keeps changing back to GridStat at different points in the video. At 9:28 this line is giving me an error in Unity and it's running as GridStats in your code.
@lynical2439
3 жыл бұрын
did you ever figure out if he renamed it or if its something different
@LettucePlate
3 жыл бұрын
@@lynical2439 No i never looked into it further. Sorry
@lynical2439
3 жыл бұрын
@@LettucePlate No worries, think I might have solved it. Thanks for the quick reply on a year old post lol
@LettucePlate
3 жыл бұрын
@@lynical2439 Np, it happens more than you think! I get notifications for comment replies and I'm on youtube daily so even super old stuff that gets replies I can see it immediately :)
@jackblakeston3319
3 жыл бұрын
@@lynical2439 Hey can you help me out? My script gives me an error because it doesn't understand what's going on the first time he writes GridStats to instantiate the grid
Though i had to do so many modification to your code to make it work for me, but if it wasn't for you .... i wouldn't have got what i need .............. maaaaaaaan you rock
This was awsome .can u show how to do a path were when the ball find a intersection, it can choose to go or not to that way, moved by a random dice roll??
At 7:35 you should leave a footnote or annotation explaining a little bit better what it is your doing within the editor. It would make the tutorial a lot more straight forward for novice's within Unity to watch your tutorial.
Hello and thank you for this video. Awesome, you have all in your mind when you are programming. I'm French and beginner in programming, but I have understood most of the outline what you said ;-) But it's difficult, normal for me. Thank you !!!
Finally a grid movement tutorial amazing! Thank you, been looking high and low for this.
Could you please provide us with a free link to the files since we already took the time to go through this?
You are amazing, thanks for this tuto man
Can I also use this in 2D??
hI can anyone help me with the source fille becasue i am lost in step variable and i am not able to accesses his patreon
(14:00) I don't know if I'm the one stupid but all 3 of the values int x = startX; int z = startZ; int[] testArray = new int[rows * columns]; aren't used at all after we make them. We create them, then do a "for (int step [...] foreach... etc and we finish the function without using those values once. even my visual studio tells me that they are useless
stumbled on this video and this is amasing, like i can't even understand how you would begin with designing this code
Hello and thank's for this very nice work. I'll try it on my project and it works good. I just have one question : when i want to follow the path to move my object, it is done instantly. How can i slow down the movement juste like you did at the end of the tutorial. Thank's angain.
@RandomArtAttack
4 жыл бұрын
Have the game object move towards a target. Look at one of my earlier tutorials (making a mini game) in which I have to animate a moving target.
@justatho8102
4 жыл бұрын
@@RandomArtAttack I've just seen the other tuto and it si just what i need, thanks a lot :D
Thank you for the tutorial
Bro i did all like you but some combinations of tiles dont work... I get different errors...they're not always the same
Instead of using ints to determine which direction to go, maybe use an enumerated data type. To the developer, it can be read as a string, but to the computer it's read as an int.
@benowen8321
4 жыл бұрын
c# does not convert enums to ints :(
@richardosborn159
4 жыл бұрын
@@benowen8321 C# does allow you to cast enums to ints int number = (int) MyEnum.value;
@benowen8321
4 жыл бұрын
@@richardosborn159 I feel dumb I never actually tried casting it. Thanks for the reply.
@richardosborn159
4 жыл бұрын
@@benowen8321 No worries. Some languages are will do the conversion automatically for you. C# likes it to be explicit. :)
@benowen8321
4 жыл бұрын
@@richardosborn159 Well that is what through me off. I had done it in c++ no bother, and in my mind I just always thought they were just ints.
How did you do to move the sphere along the path? I'm sorry, I really thought I could figure out alone, but after banging my head on it for a few hours, I still haven't figured out. It's the only tutorial I found which is doing what I really want, now I just need to make the object move. If you can just explain really quickly, I would be so grateful. Thank you
@RandomArtAttack
4 жыл бұрын
That is outside the scope of the tutorial, but I do cover this very concept in my minigame series. Look for the video when I talk about moving targets.
@cratuss2661
4 жыл бұрын
kzread.info/dash/bejne/pYuBy5Oqf72eqLA.html that should be the video he mentioned but even with that its very hard to transfer it on this project... tbh i didnt got it working :(
@viscarious1
28 күн бұрын
@@RandomArtAttack Did you ever make a tutorial that builds on this one?
@RandomArtAttack
28 күн бұрын
@@viscarious1 No, to be honest KZread kind of killed all the enjoyment of making videos. The algorithm makes it so I felt like I was having to make specific types of videos and it just killed any momentum I had. I may come back someday, but unless youtube stops trying to make creators think they need to do weekly uploads, with clickbaity titles and thumbnails, I don't think I want to come back. :D
@viscarious1
28 күн бұрын
@@RandomArtAttack I can appreciate that. Could you go into rough details with how to set the target position, and transfer the path list to a game body?
Hi everyone, If you are working on a 2D game, you will find the instantiated objects not showing properly. That's because we set the transforms 'x' and 'z' in this tutorial, but for 2D 'flat' games to instantiate the grid prefabs you may want to set 'x' and 'y' instead. In short, this like instead of the one given in the tutorial (please note I used slightly different var names! GameObject go = Instantiate(gridPrefab, new Vector3(leftBottomLoc.x + scale * i, leftBottomLoc.y + scale * j, leftBottomLoc.z ), Quaternion.identity);
Can´t you move diagonally?
Very impressive, thank you so much
Where to create the grid prefab? is it a sphere prefab?
@RandomArtAttack
5 жыл бұрын
Great question, it is just an empty. If you want to use a sphere you can, and just turn off rendering, but it will be slower.
@beaverjoe9171
4 жыл бұрын
I guess he used the Gimoz. you can find on your inspector. The default is one gray white cube
druidstone's movement includes diagonal movement, can you make another tutorial implementing diagonal movement?
@RandomArtAttack
4 жыл бұрын
I have a laundry list of tutorials I would need to get to first, so basically I would do the same principle but check 8 directions instead of 4. Sorry I can't make a full tutorial, but I hope that is at least a helpful start.
@CasualCosta
4 жыл бұрын
It's probably a classic A* (A star). There are A LOT of tutorials on them around.
One type of game on my list is a tactics. I would love to practice with a remaaster of kartia. That would be fun. Your visual explanations are great and help, I can't always imagine when people just explain with words. But this reminds me of minesweeper
Great tutorial. I wish you would playtest it more. Build a grid, playtest. Start at 0,0 , playtest with debugger to check values, check all nearby squares, playtest values. Now we are using lists, vars, step - 1, step +1, just step, test direction - 1, writing a function that will check something once but we will put it in the loop later, for 30 minutes, on yeah, you forgot to put Y value in the array on 12:22 .. It would actually be much easier to copy paste the code and step through with debugger, than to follow along.
could u please provide the script?? I wrote it but for some reason, it didn't work
@Programm4r
4 жыл бұрын
Well, that doesn't help anybody out. Be specific, and someone can help you out.
The tutorial was going great until you skipped some crucial steps. Suddenly you have a new object called GridGenerator and one called GridObject which were never explained. I'm not sure this was your intention, but the impression it gives is that we need to support you on Patreon to actually be able to follow the tutorial
@malikbenslimane2873
4 жыл бұрын
He said that he skipped it, it's just an empty GameObject, a parent for the gridprefab and also contains the gridstat script.
@malikbenslimane2873
4 жыл бұрын
And gridobject are the yellow spheres
@bensontsai1166
4 жыл бұрын
@@malikbenslimane2873 but i got null NullReferenceException what should I do?
@akarahexels677
4 жыл бұрын
I don't know if you still want it, but the error must be on your gridPrefab. Go into Unity, drag your Prefab into the Hierarchy and drag the Grid Stat script, as Malik Ben said. After that, turn it into a prefab again and it should work.
@samgamgi
4 жыл бұрын
@@akarahexels677 and Malik Thank you. As my first project, I tried replicating this video, but I knew nothing from Unity at the time and got lost at this part. Now, after some Unity beginner videos, instead of nothing, now I know next to nothing(big difference!), and was able to follow your instructions and create the grid.
I know this is an older video but a follow up on linking an object like the sphere to the grid would be amazing
the code you wrote, is different to the example u showed at the end, you have a variable called "object to move" but when your guiding us through your logic, you don't seem to have this variable in your script. So where is the line of code that actually tells the game to move the object? Also in scene, you script is GridAI not GridBehavior.... just a little lost, if you could point me in the direction that would be great, thanks
@memebox9189
4 жыл бұрын
actually in my situation, I do not need to move something, I just need to find something closest to a given grid position
What's the point in checking y + 1 < rows && gridArray[x, y + 1]. If y + 1 < rows is true then so is gridArray[x, y + 1].
Hey. I followd the whole tutorial but now I see the script is changed at the ending. Could you give me the code I'm missing.
@mobeenahmed361
7 ай бұрын
did u find..?
excellent video bro can create one list reproduction of this type of game?
at 12:45 you bring up a visualisation and talk over it but the picture doesn't change. So its a bit pointless, it doesnt explain anything
I love this video! now it is one part of the grid based movement I have been looking around how to project the grid onto the terrain, the way they do it on xcom, druidstone, phoenix point. I guess this might be shader based, but if you had any insight on how to do it and feel like making a tutorial it would be awesome!
@lyl14ghost
3 жыл бұрын
same here! Xcom is my main inspiration.
@DarthStevenus
3 жыл бұрын
Same, trying to make a proof of concept for a kind of XCOM style mech fighting game. Got the camera down, and I've got a simple "mech" made of cubes and other primitive objects. But I can't find a good grid tutorial.
can you do this again but with a hex based movement
@RandomArtAttack
4 жыл бұрын
Sorry for the late response... maybe... I think it would be similar except you would need to check 6 directions instead of 4.
@kosta1570
4 жыл бұрын
@@RandomArtAttack 8
@Zerossoul
4 жыл бұрын
@@kosta1570 6 sides on a hexagon, 8 sides on an octagon. So in this case, 6.
In testdirection i got error with case:4 index was outside the bounds of the array...
@Zerossoul
4 жыл бұрын
He changes it up at the end of that section. Pay close attention at 12:00. in about 5 seconds from then, the code changes a lot.
thanks good video but bit confusing make a prefab with the gridStat script on it have an empty at 0,0,0 with the gridBehavoiur script on it
can u make tutorial game for this movement. with touch or with mouse clicking.. drag and drop some heros and it will be 2d image to 3d object to gameboard like clash royal.. and they will start move.. it can be soldiers movement with different guns.. not have to be heros like clash royale
@RandomArtAttack
5 жыл бұрын
Maybe in the future, but right now I have several other tutorials scheduled.
@vexingcoder3437
4 жыл бұрын
dude.. that is so specific haha just find some tutorial for each of these features or discover it your own and merge them into a game.
@kerim404tt5
4 жыл бұрын
@@vexingcoder3437 dude im new on coding 😇 soo i need see how it works excually- im learning with my eyes not with brain 😋
@vexingcoder3437
4 жыл бұрын
@@kerim404tt5 well if you say so just don't stop on learning ;)
Do you quickly edit out yourself fixing your mistakes because you make a mistake but fix it unbelievably fast its an amazing skill. Also very nice code i struggled to keep up but will try my own version someday you give good inspiration
So... there's no "follow path" tutorial"??
Thanks for tutorial but it doesn't work ((( created cube prefab with gridStat but it doesn't find anything.Please,help !
@loganh2735
3 жыл бұрын
You have to put it on THE prefab, not the object in it. Open the prefab editor by double clicking, click the topmost object in the left panel, then apply the script to that.
great im testing path finding on UE5 to see different methods and compare their performance
Really good alternative for the A* algorithm and the production quality is on point. You got yourself a new subscriber ! However I might have a suggestion for increase performances. Do two list of GameObject, one for the visited cells and one for the unvisited cells. That way, on your SetDistance method you don't have to check which is already visited and which isn't. It'll be better for multi-threading efficiency.
@PorterNielsen
4 жыл бұрын
Brilliant, that is such an elegant solution. Using your improvements I think I could actually extrapolate this for pathfinding in 3-dimensions and have it still run optimally.
@floriancazacu4504
Жыл бұрын
Also, GetComponent is probably the least performant way to do this.
I will iterate again for those sorting by new: DO NOT USE THIS TUTORIAL. IT WILL NOT TEACH YOU HOW TO MOVE ANYTHING ON A GRID. To find that out he wants you to pay money to access his Patreon files or whatever.
@turceanucosmin7223
3 жыл бұрын
it's not that hard anyways ffs
Awesome!
7:40, kinda confused on what you are meant to do from here
@RandomArtAttack
5 жыл бұрын
Specifics will help me clarify. What exactly don't you understand so I can help?
@SniperSpy10
5 жыл бұрын
@@RandomArtAttack NVM, got it working, the IDE was having trouble changing the name of the script
@RandomArtAttack
5 жыл бұрын
@@SniperSpy10 I am glad you got it working, I am surprised by how many times that has bite me in the butt. I know the name of the error by heart at this point, but I still forget to catch it on my own.
sry but isnt it kinda pointless to make a whole video about the Grid Movement if you skip the actual Movement part? I mean you generate a grid ok.. but how can i move my Player arround e.g. with mouse or WASD pls help x.x
This was interesting but you leave out the part of the script that has the sphere and moving the sphere along the path. I guess that part you expect for people to find out on their own but that doesn't make for a very good tutorial. Mainly because I can't see it work for my self. Please release another smaller video explaining how you put the Object To Move, Speed, Move, and Move Step variables in. Thank you for the video.
how do we do this in roblox
Don't waste your time if you're not one of his patreon the video isn't finish
I litteraly stopped the video in the middle just to make sure I liked the tutorial! You are a legend bro the way you explain and clarify things :o
GridAi?
Good presenter but poor tutorial - recommend skipping this especially if you're very new to Unity as you won't get anything functioning from following it step-by-step
Luckily I didn't follow this tutorial in my game instead I follow this in a new unity project. The code for generating the grid works but the pathfinding is not even working. the path only adds one object. I kept repeating the video just to make sure I did not make a mistake or some missing line of code but I didn't. The video just keeps jumping around without explanation. I'm not usually the person who complains but man this just frustrates me. You let me down, man. I was having high hopes when I found this video. But you know what I'll just keep in mind how you visualize the pathfinding and I thank you for that. bye~e
GitHub repo?
Probably could make it smoother by evaluating all 8 directions instead of just 4. Gonna do some tweaks for performance and memory. Thanks for the general idea though! *Update* Here is a sample of my modified A.I. from this follow-along tutorial. I've worked with 2D arrays before, but never A.I.. The A.I. is set to randomly patrol. Enjoy. kzread.info/dash/bejne/qXd6yNeylJO1lrQ.html
1. use enum instead of int 2. code should be more readable 3. for int i=step, step > -1, step-- ?? you have reduced step in it then why have you used i
@lulasz_
2 жыл бұрын
yeah.. i am asking that myself too
UNCOMPLETED TUTORIAL! People who liked this video didn't even try to implement it, there is no "custom movement" script in this tutorial only grid and path-finding scripts.. you will have to rely on yourself to create it and link the path generated by the path-finding script to your custom movement script. He modified the script to showcase the project at the end of the video without showing us how to do it in a tut video that is literally titled "CUSTOM MOVEMENT on a Grid and Path-Finding".
it tok me 6 houers make this work. . . he uses Colums as X and Rows as Y . . .
@holliscf
Жыл бұрын
Holy shit, ive going over this the past hour thank you for your comment swapped these and fixed the bug
I lost my brain cells after watching this.
Gracias, me tome 3 horas en algo que me soluciono un comentario XDDDD
Wow, this was total trash. Patreon, what a great creation.
27:03 very suspicious cut
Nice, don't work.
Appreciate the tutorial but it's far too fast and you make so many mistakes it's difficult to follow but I got there in the end cheers. No way a beginner would be able to follow this with the mistakes.
1 year ago this vid was uplaoded :)
cloumns
what a waste of time
Please don't make videos like this anymore
cloumns