Тёмный

Point & click 2D grid movement in Godot 4 using AStarGrid2D 

Retrobright
Подписаться 1,5 тыс.
Просмотров 37 тыс.
50% 1

Опубликовано:

 

20 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 116   
@Slipy61
@Slipy61 9 дней назад
Finally, a good example of actually using the grid. I'm planning on making a turn based game with limited movement, but I can take it from here. Thanks for the fantastic starting point!
@domedevep
@domedevep Год назад
ohhh dude, i just changed the movement styled from a grid to a free movement because i couldnt do this :(. Keep making tutorials like this, you're so valuable for newbie game devs like me!
@lol3xtrach3353
@lol3xtrach3353 2 месяца назад
Hey man I just wanted to let you know that I'm in love with you for making this tutorial. Exactly what I was looking for, concise, clear, fast...be still, my heart
@NicoFye
@NicoFye Год назад
Instant like for showcasing the result at the start of the video
@JorgeFigueroa-lx6rh
@JorgeFigueroa-lx6rh 4 месяца назад
This video was so valuable to me right now after 2 days trying to figure out how to properly do isometric grid movement and running into walls. By obligation, I have to leave this comment to let you know that a random stranger on the internet appreciates you. Thank you, so much!
@2omelettes
@2omelettes 2 месяца назад
Absolute godsend, you're singlehandedly preventing me from going bald from frustration with this tutorial. Thank you so much.
@JohnSane
@JohnSane 7 месяцев назад
Awesome! Now a third video would be great which combines the A* Point & Click with the 2D Movement video. Keep up the good work!
@Cesardevart-dc1pz
@Cesardevart-dc1pz 8 дней назад
Thank you! This video is very useful, I'm starting to work on a roguelike game, and this is a great beginning.
@pixboytv
@pixboytv Месяц назад
I love how you print stuff and the screen and explains everything. Great tutorial and amazing teacher.
@Rafael-wr7wi
@Rafael-wr7wi 7 месяцев назад
Great tutorial, finally understood AStargrid2D after your video
@jorie100
@jorie100 Год назад
i LOVE YOU, THIS IS EXACTLY WHAT i WANTED. It was very interesting because my game has 3d graphics and I was able to use this using a gridmap instead, converting the vector2 to vector3 and viceversa, and shooting a raycast from the camera to know the position. Since my 3d game doesnt have height or layers of land, I only nedeed to move the character on a 2D plane and I also nedeed to do it with squares and without diagonals just like you but in 3D, and this solution is working wonders. Thank you so much.
@kindavacant7843
@kindavacant7843 11 месяцев назад
Great overview, wish I'd seen it five months ago when I was trying to work it out. Using single tiles instead of atlas one can define a 'solid' via tile number instead of 'walkable' which is handy for an active map where tiles can change from not solid to solid. 'Tweening' (IE: tween.tween_property($%playerSprite,"position",nextTileLoc,.4) can also be used instead of process.
@Automageddon
@Automageddon 9 месяцев назад
I've been struggling with this for days until I found this video, thank you!
@socklesshobo
@socklesshobo 3 месяца назад
Really great tutorial. Thank you! I hope you got back to making tutorials, since everything was really direct and useful.
@alistormccoy1953
@alistormccoy1953 9 месяцев назад
Heya, just popping in to say that AstarGrid2D has a property "offset" which allows you to set the local coord for each tile during setup instead of having to loop over and adjust them individually like you did near the end ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-DkAmGxRuCk4.html Cheers!
@DrZell
@DrZell 2 месяца назад
Just exactly what I was looking for! Thanks for the tutorial!
@nyx3m
@nyx3m Год назад
You are doing a great job , taking on the topics which aren't yet touched, please keep making videos for our new thriving community. We all are rooting for you 🎉
@KommissarAlexander
@KommissarAlexander 8 месяцев назад
Amazing work, I was breaking my head trying to do / find somethjng like this
@BUTTERFLY-eo6ob
@BUTTERFLY-eo6ob 2 месяца назад
very good, simple and helpful thanks man
@timflatus
@timflatus 9 месяцев назад
Great tutorial. You may have convinced me that AStarGrid isn't the way I want to go as it looks complicated, which often means computationally expensive. I have a lot of moving objects.
@CosmoCodez
@CosmoCodez 5 месяцев назад
Thank you for the tutorial it really helped there wasn't even one for Arrow keys. And now for Point and click Thank you so Much.
@AndrewKwiatkowski
@AndrewKwiatkowski Год назад
This is quite amazing, so many really rubbish tutorials on here. This one is very well made. very clear. How about a tutorial on how one would do this on a 2d map that has gravity. Rather then North/South, a Up and Down type view point
@sailorjune2121
@sailorjune2121 11 месяцев назад
This is why it’s important to read the docs I spent all yesterday trying to implement a star from scratch 💀💀💀 Godot rules
@zirklutesKerpa
@zirklutesKerpa 11 месяцев назад
This is an amazing tutorial, thank you so much!
@speggeri90
@speggeri90 3 месяца назад
I used this same for hex based grid, but there is an issue that sometimes the diagonal movement slides in between the cells. For example, if I have a cell [0,0] and go to cell [1,1], it slides there directly without going through cells [0,1] or [1,0] first. I'll write here, if I'll find out why it does that. Edit: I believe hex grid is not possible to use as is with AStarGrid2D. You need to make custom function that connects all 6 points to adjacent cells.
@dougsaylor6442
@dougsaylor6442 10 месяцев назад
Really great video! This helped a lot. :)
@forexdisk9693
@forexdisk9693 2 месяца назад
awesome tutorial!!!
@purplepixeleater
@purplepixeleater Год назад
any chance we can get a tutorial on how to do this with isometric tilemaps? Does it work the same?
@CptProtagonist
@CptProtagonist 6 месяцев назад
currently testing this with an isometric map and it seems to be working the same so far
@Hauness349
@Hauness349 9 месяцев назад
How would you write the proper function to only allow you to move one space (or "action" is what I'm going to call it in the game) every 5 seconds. Also, do you have any recommendations for learning these different functions and variables so I can know what I'm looking for in the future and don't have to bug you or rely on tutorials?
@CaptmagiKono
@CaptmagiKono 11 месяцев назад
Oh yeah, just one minor thing after finishing the line-drawing part. You can have the line get removed from the screen when arriving at the destination by just clearing the "current_point_path" array of values. Worked for me just putting "current_point_path.clear()" on the line before setting "isMoving" to false.
@ТарасДзебчук-и1ы
@ТарасДзебчук-и1ы 4 месяца назад
I just move the line on -10 z index when finish moving
@prechabahnglai103
@prechabahnglai103 Год назад
Been looking for this. THANK YOU SO MUCH!
@moboy-i1z
@moboy-i1z 9 месяцев назад
Hi, great video you made. Will there be a sequel video about animation on this code using AnimationTree? And I would like to see how to use flip_h, how to change the movement speed, and how to leave the character position back-idle, front-idle, side-idle after movement. I tried animating the character, for some reason it doesn't work. I looked for a video - I couldn't find one!
@agam3z153
@agam3z153 4 месяца назад
did u solve the problem ?
@구영민-o8h
@구영민-o8h Месяц назад
THANK YOU... 감사합니다... THANK YOU... 감사합니다... THANK YOU... 감사합니다... THANK YOU... 감사합니다...
@stinghouseproductions8502
@stinghouseproductions8502 Месяц назад
Thanks for making this.
@stinghouseproductions8502
@stinghouseproductions8502 Месяц назад
Really though, you made this process super easy for someone who's never messed around with AStar before. I can't thank you enough.
@RetroBright262
@RetroBright262 Месяц назад
@@stinghouseproductions8502 Thanks for the kind words
@hachetrescomacatorce2340
@hachetrescomacatorce2340 4 месяца назад
you are awesome bro, thanks!!! greetings from colombia
@andresgrimminck8674
@andresgrimminck8674 6 месяцев назад
Do you know if it is possible to put the cost to every tile and let the algorithm take that into account when finding a path?
@NoRageStudios
@NoRageStudios 9 месяцев назад
Thank you for the tutorial, is there an easy way from your script to be able to move the character if we are still pressing the mouse button ? I mean, I want the player to "follow" the cursor if I am still pressing the mouse button. Thank you
@NoRageStudios
@NoRageStudios 9 месяцев назад
I found a solution, if someone need it 1. remove the func _input(event) function and its content. 2. add those two functions in your script : func _process(delta): if Input.is_action_pressed("move"): get_player_path(); func get_player_path(): var id_path = astar_grid.get_id_path( tile_map.local_to_map(global_position), tile_map.local_to_map(get_global_mouse_position()) ).slice(1) if id_path.is_empty() == false: current_id_path = id_path
@agam3z153
@agam3z153 4 месяца назад
@@NoRageStudios did u know how to play animations in different directions because i don't know how to get direction to play right and left animations
@renardfele
@renardfele 4 месяца назад
​@@agam3z153 I am sorry I haven't worked on that project since a long time and I had to reinstall windows. I haven't kept my Godot Projects 😟
@Dustifer
@Dustifer 5 месяцев назад
Ive been following this, basically, and its been very helpful. I have one small problem... So, I changed it so per mouse click you only move 1 tile, like your previous video with the wasd keys But the first move can still be diagonally for some reason, every move afterwards can not. Ive been at it for 2 hours and have not been able to fix it... any idea's? Edit: actually, every first click the movement is incredibly wierd and dubble and off center and slightly diagonally. I have no idea what is going on because afterwards everything is normal...
@adamkerr6853
@adamkerr6853 Год назад
Hi, thanks for this. Just what I needed. I'm having a small bug where the top part of the tile map doesn't return a click value (top 3 rows or something) but the ones underneath all seem to work just fine. I could design around it I suppose but I don't suppose you know what could be causing it do you... (they're all the same tile and this was a problem introduced before the "walkable tile" was introduced.) I will add that is this the first thing I did in the project and the only difference I've made so far is my tiles are 32 x 32 which the code is adjusted for.
@hamtown4757
@hamtown4757 5 месяцев назад
Hi, im doing this in isometric view, and for some reason whenever i click on the tile directly next to the player it moves to a tile that is diagonal instead. im guessing the mouse is off or something. im kinda lost.
@palatonian9618
@palatonian9618 17 дней назад
I cant figure out why my sprite/character is moving only on the intersections of cells and not the cells rhemselves and in trying to make a board game so its really throwing things off
@kvcs-pl
@kvcs-pl 4 месяца назад
This is the movement I'm looking for my game too, but can't find any tutorials on how to make the character face the direction they're moving. Can you make a tutorial on it, or give some advice on how to animate in this movement style? Thanks in advance!
@ParryMime
@ParryMime 10 месяцев назад
Excellent tutorial!
@plyr0
@plyr0 9 месяцев назад
Great tutorial! Thank You!
@CutyDina
@CutyDina 7 месяцев назад
love this tutorial! is there a way to keep moving until it crashes with any obstacle? like sliding?
@brandonjacksoon
@brandonjacksoon 8 месяцев назад
Thanks for the tutorial! Liked and subscribed!)
@spiritnet6219
@spiritnet6219 Год назад
Hi, very interresting implementation.Just one question plz: how do you manage obstacle ?
@abdou023
@abdou023 6 месяцев назад
I'm facing a problem that the path doesn’t appear after the first click. The navigation itself works perfectly but I have to press the mouse a second time in order for the path to show and after that it works fine.
@A_Veget4ble
@A_Veget4ble 5 месяцев назад
Hello I really appreciate the tutorial, but do you know how to add a limit to how far the player can travel?
@palatonian9618
@palatonian9618 20 дней назад
I think the limit should be inherent to the astargrid you create?
@JD-us8xw
@JD-us8xw 4 месяца назад
Is there a way to adapt this to run on multiple tilemaps?
@Gandalf_Le_Dev
@Gandalf_Le_Dev Год назад
Great tutorial, thanks :D
@AlexandroTrevisan
@AlexandroTrevisan Год назад
Nice and to the point! I like that!
@CaptmagiKono
@CaptmagiKono 11 месяцев назад
Thanks, this was very helpful.
@StandAlone3
@StandAlone3 8 месяцев назад
I'm running into a weird issue where the first time I go to move the character, it sets the target position to (0, 0) for the first couple of seconds, then it corrects itself and starts going the right way. After that it doesn't do it again on subsequent moves.
@jablao
@jablao 9 месяцев назад
great video, helped me a lot, thank you
@ichlalsulbulqiah1974
@ichlalsulbulqiah1974 6 месяцев назад
Thank you so much for your tutorial, it's really helpfull
@ReddleyYT
@ReddleyYT 9 месяцев назад
I'm getting an error that says "Invalid call. Nonexistent function 'get_call_tile_data' in base 'TileMap'.". I'm at 14:46 in the video trying to run it just as you did a moment later. I'm new to scripting and Godot, so things are a bit confusing for me at the moment. Though, it sounds like to me it could be because my TileMap is set up incorrectly, or perhaps it's because it's a child to NavigationAgent2D, idk.
@MrHsktoto
@MrHsktoto 9 месяцев назад
try to add @onready var tile_map : $"../tilemapdirectoy" and if you already have it check if the path is good and if the script find it way to this actual path that might be the problem
@cr0wmatic
@cr0wmatic 11 месяцев назад
would anything change when using a hex tilemap instead of a square tilemap?
@NomarOmens
@NomarOmens 10 месяцев назад
Hi, I enjoyed this tutorial but encountered an issue where you cannot move to the solid objects but the player character will still move THROUGH non-walkable objects to get to their destination. My code is the same as in the video but I will update this comment if I find out what's wrong.
@OhNoes_TV
@OhNoes_TV 3 месяца назад
Mine walks right through them too
@FuzzballStudios
@FuzzballStudios Год назад
I think the preferred syntax for checking if a boolean is false is actually `if not current_id_path.is_empty():` rather than checking if it’s equal to `false`.
@ubit123
@ubit123 Год назад
Wanted to say the same 👍. No way I would let this pass through code review 😊
@DanJuega
@DanJuega 9 месяцев назад
@@ubit123 why tho
@deepfriedtuba
@deepfriedtuba 6 месяцев назад
Could you make a video applying this to multiple selectable agents? Like RTS style movement
@TheIronicRaven
@TheIronicRaven Год назад
Any chance you would make this for 3D? For GridMap?
@DrNabeel20
@DrNabeel20 11 месяцев назад
Super usful! thank you very much
@ubit123
@ubit123 Год назад
is_moving is redundant. If Targetposition is not null you are moving. When you reach intermediate destination you pop new target position. When you reach final position, there is nothing to pop and you set target position to null.
@MrHsktoto
@MrHsktoto 9 месяцев назад
great explanation even as a godot beginner it feel fluid and thanks for that . i'm struggling to get it work with a tile based movement at the same time both together result in a problem with the var is_moving = bool because i already us it at var is_moving = false for the tiles based movement how could i combine this two together ?
@Lets_Get_This_Bread
@Lets_Get_This_Bread 8 месяцев назад
No matter what I do I get an error on astar_grid.cell_size = Vector2(32, 32) Only difference is I am using a 32 x 32 tileset, any assistance would be appreciated
@longuemire748
@longuemire748 11 месяцев назад
Thanks for this tutorial, Does it also work for isometric?
@RetroBright262
@RetroBright262 11 месяцев назад
Isometric tile maps require a separate implementation; expect a video soon. 🙂
@longuemire748
@longuemire748 11 месяцев назад
@@RetroBright262 Thank you :), The code is very intuitive.
@JoksterStudios
@JoksterStudios 10 месяцев назад
great tutorial - just followed it on an isometic tileset and worked like a charm except the final path drawing@@RetroBright262
@Voxet1
@Voxet1 10 месяцев назад
i will say the pathing was a little odd, alot of the time it felt like it wasnt using the best possible path at all @@JoksterStudios
@agam3z153
@agam3z153 4 месяца назад
@@RetroBright262 can u make an animation guide for this tybe of movement plz i need it so bad
@thecumscrubber
@thecumscrubber 4 месяца назад
This is the best tutorial for AStarGrid2D, it has really helped me out. Would anyone know how to how to not allow diagonal movement when moving sideways but allowing diagonal movement when moving up and down? My issue is I am uing a isometric grid, and using hexagon shapes. This is also affecting how the draw_polyline is showing up on screen (but that may be fixable), so not as concerned about it yet. Thanks!
@ubit123
@ubit123 Год назад
15:37 why add offset? Can you iterate from tilemap.get used rec.position.x to tilemap.get used rec.size.x?
@Myko82
@Myko82 Год назад
That would be too many tiles, but you could iterate from rec.position.x to rec.end.x
@sajberkg
@sajberkg 5 месяцев назад
is the code available somewhere? :)
@IVThesimple3436
@IVThesimple3436 5 месяцев назад
was wondering if anyone knows how I can set the blend position of an animation tree using this method for movement so the game knows which direction the player is moving? I attempted to use velocity but it seems the engine doesn't think the player has any velocity using the movetowards method for global position, I attempted to use the player having no velocity to set the idle state as a test and the game always thought the player was idle, though this could be an error on my part I attempted to set the blend position based on the players velocity.x and velocity.y normalized and the animation never changed which again leads me to believe the engine does not detect this method as change in velocity, any help as to how I can set the blend position would be much appreciated
@agam3z153
@agam3z153 4 месяца назад
did u find it out ? i need to know how which direction the player is moving so i can play the animation right and left
@ArgonZavious
@ArgonZavious 10 месяцев назад
Thank you!
@Epeters022
@Epeters022 Год назад
awesome tutorial! It was really helpful setting up my ai to move around the tilemap. My only problem is that the ai ignores collision with each other. Any tips for how i could dynamically update the tile an ai currently occupies so the path updates around it? All my attempts to use set_point_solid seem to have no effect.
@RetroBright262
@RetroBright262 Год назад
Sounds like an interesting subject for the next video, I already have a project set up for this so stay tuned 🤔
@Jonathan-sk5wy
@Jonathan-sk5wy Год назад
Make updating the collision info on the map part of the movement function!
@martin-gaming
@martin-gaming Год назад
I found a way to disable the tiles the unit is on bit this can result in huge spaces being blocked, especially if units are smaller than the tile and an entire tile gets blocked or bigger than a tile then it can disable multiple
@Epeters022
@Epeters022 Год назад
I ended up using a similar approach. My biggest issue is when 2 actors intersect they end up course correcting in the same direction in an infinite loop and never reach their destination@@martin-gaming
@martin-gaming
@martin-gaming Год назад
@@Epeters022 I'd say you let the pathfinding as it is with terrain/wall Collison and crrate a diffrent system for unit avoidance and optional some smoothing, steering behaviors, etc
@papierk0rp
@papierk0rp Год назад
This was really helpfull thanks a lot.
@Drachenbauer
@Drachenbauer 9 месяцев назад
the player sprite should better be an extra graphic with transparent background to prevent vovering grass-pattern outside the actual character´s body.
@rockmystyle
@rockmystyle Год назад
Nice video, but I found a bug. The feature when you cant change target during moving doesn't work with your code. Just put inside the 'input' function one line and it will work perfect: if is_moving == true: >return
@RetroBright262
@RetroBright262 Год назад
The project shown in the tutorial specifically allows you to overwrite the path array during movement, but only navigates to the new target after it has finished moving to its current target when already moving. If you don't want the player to change target whilst moving than what you have proposed might work. It's not a bug, it's a feature.
@guuiswere
@guuiswere 2 месяца назад
@bizidru
@bizidru Год назад
why didn't you want to use it Line2D? It's much easier to use line drawing
@purplepixeleater
@purplepixeleater Год назад
Its slower.
@peace__duke
@peace__duke 5 месяцев назад
source code pls
@puleroxd4116
@puleroxd4116 6 месяцев назад
My code says invalid operands Vector2 and Vector2i in operator ==. I only managed to do the tutorial until 10:13
@puleroxd4116
@puleroxd4116 6 месяцев назад
fixed apparently my global position was not 0,0 but 167,198 so all i had to do was subtract that and for some unknown reason that fixed the Vector2 and Vector2i... not exactly sure how that works but its working now
@shahnet2201
@shahnet2201 Год назад
Hi can you make a grid#tile movement like advanced war game
@iluviatharelbardo8901
@iluviatharelbardo8901 Год назад
hello bruh. I'm trying to start something similar to an advance war too. I suppose you can use this AStargrid in the tilemap and find a way for the units to interact with it by blocking paths, instead of having a grid for each unit. Otherwise I don't know how I would detect the other units in the game, allies and enemies. I'm still learning
@pepsipwns666
@pepsipwns666 Год назад
Wondering how well this scales to large 500*500 tile maps, I used the NavigationAgent/Tilemap Navigation and the grid ended up lagging at a large size clicking a far tile. So I ended up baking a navigation across my entire map (not grid based). I wonder if I can achieve the grid movement with this, is it more performative? Have you tried with a larger map size?
@werewolfdragon4740
@werewolfdragon4740 10 месяцев назад
probably pretty late but I can give you a relative answer, for any potential future searchers. . The problem is that with pathfinding the longer a distance the "character" needs the travel, the exponentially more blocks need to be calculated. for instance, searching in a 50x50 block will require approximately half the squares searched to find the "correct" square if they're on opposite sides, that would be 1250 blocks checked for one single pathfinding operation. a 500x500 could involve operations upward of 12500 blocks searched, small wonder that there's lag involved, the algorithm by default isn't really designed for sizes that large. For a built-in solution, if you enable jumping (set_jumping_enabled ( bool value )) then the program will assume that there is no weighting in the pathfinding (which means it will not check each individual tile and instead make straight lines across gaps of non-blocked tiles. this comes with the drawback of the pathfinding completely ignore weighting (which is obviously not a problem if you don't include any) if you're not using the built-in pathfinding, or weighting, this will obviously not help. so instead I would recommend giving a pathfinding distance limit, say 100 blocks so that it loads the pathfinding in chunks and merely walks in the correct direction until the final "path" can be found. unless your terrain is extremely convoluted, this should be a good solution for any small to medium size game. (as in not years of progress) alternatively to the first solution, you can turn off jumping for short distances, and turn it on for long ones. I don't know how effective this would be, but it seems like it should help. other than that I would recommend writing a pathfinding algorithm of your own that is better optimized for dealing with your particular troubles, I can't really provide any advice for how to tackle that, but it's pretty much the nuclear option, and shouldn't be necessary unless you really just have a maze of a level with a lot of intricacies. if you are unsure what weighting is: a weight in pathfinding is effectively the "cost" to go one block. it's one to go in any direction on any tile by default. a pathfinding algorithm will always try to find the lowest "cost" path. going around tiles that cost a lot in favor of cheap tiles. this is useful when considering tiles that would slow the player down, as you can increase their weight to make the algorithm naturally avoid them unless it would be faster to simply go through. you can also change it to where going diagonally is slightly more expensive, to compensate for it being a longer distance, as with the default method, diagonals are extremely preferred due to covering twice the distance at no extra cost (1.5x cost is the standard approximate)
@pepsipwns666
@pepsipwns666 10 месяцев назад
Thanks for your very detailed response. I basically came to this conclusion that it was too many tiles to calculate. I ended up baking a navigation mesh over my map instead of per tile, so its large polygons that fill the map, the movement is more 'diagonal' than I would like, but it certainly reduces the number of steps in the path drastically, so I no longer have lag. I did use the 'jumping' technique with the first solution and it still had lag. I probably could have done what you said about chunking the path into smaller sections, that's a great idea. @@werewolfdragon4740
@ТарасДзебчук-и1ы
@ТарасДзебчук-и1ы 4 месяца назад
Great tutorial! But you can use "if not id_path.is_empty()" instead of "if id_path.is_empty() == False", I think its a little faster if you have big script
@agam3z153
@agam3z153 4 месяца назад
14:56 i but " , " after y and it worked great tutorial btw 🤍 can u make tutorial about animations in this style of movement ?
Далее
Using Composition to Make More Scalable Games in Godot
10:13
I Made the Same Game in 8 Engines
12:34
Просмотров 4,1 млн
TAS Explained: Super Mario Bros. 3 in 0.2 seconds
19:39
The Worst Part of Gamedev
9:32
Просмотров 16 тыс.
How Games Make VFX (Demonstrated in Godot 4)
5:46
Просмотров 352 тыс.
Why you Draw Bad Assets || 2D Game Art
13:00
Просмотров 76 тыс.
Optimizing my Game so it Runs on a Potato
19:02
Просмотров 626 тыс.
Programming a tactical strategy game in Godot 4
14:50
Creating SMART enemies from scratch! | Devlog
5:40
Просмотров 343 тыс.