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

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 พ.ย. 2024

ความคิดเห็น • 120

  • @domedevep
    @domedevep ปีที่แล้ว +28

    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!

  • @NicoFye
    @NicoFye ปีที่แล้ว +6

    Instant like for showcasing the result at the start of the video

  • @JorgeFigueroa-lx6rh
    @JorgeFigueroa-lx6rh 5 หลายเดือนก่อน +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!

  • @Slipy61
    @Slipy61 หลายเดือนก่อน

    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!

  • @lol3xtrach3353
    @lol3xtrach3353 4 หลายเดือนก่อน +3

    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

  • @alistormccoy1953
    @alistormccoy1953 10 หลายเดือนก่อน +7

    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 th-cam.com/video/DkAmGxRuCk4/w-d-xo.html Cheers!

  • @Cesardevart-dc1pz
    @Cesardevart-dc1pz หลายเดือนก่อน

    Thank you! This video is very useful, I'm starting to work on a roguelike game, and this is a great beginning.

  • @2omelettes
    @2omelettes 3 หลายเดือนก่อน +1

    Absolute godsend, you're singlehandedly preventing me from going bald from frustration with this tutorial. Thank you so much.

  • @Rafael-wr7wi
    @Rafael-wr7wi 8 หลายเดือนก่อน +1

    Great tutorial, finally understood AStargrid2D after your video

  • @JohnSane
    @JohnSane 8 หลายเดือนก่อน +2

    Awesome! Now a third video would be great which combines the A* Point & Click with the 2D Movement video. Keep up the good work!

  • @anonykat31
    @anonykat31 2 หลายเดือนก่อน

    I love how you print stuff and the screen and explains everything. Great tutorial and amazing teacher.

  • @kindavacant7843
    @kindavacant7843 ปีที่แล้ว +4

    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.

  • @jorie100
    @jorie100 ปีที่แล้ว +6

    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.

  • @socklesshobo
    @socklesshobo 4 หลายเดือนก่อน +1

    Really great tutorial. Thank you! I hope you got back to making tutorials, since everything was really direct and useful.

  • @BUTTERFLY-eo6ob
    @BUTTERFLY-eo6ob 3 หลายเดือนก่อน +1

    very good, simple and helpful thanks man

  • @DrZell
    @DrZell 3 หลายเดือนก่อน

    Just exactly what I was looking for! Thanks for the tutorial!

  • @Automageddon
    @Automageddon 10 หลายเดือนก่อน +1

    I've been struggling with this for days until I found this video, thank you!

  • @KommissarAlexander
    @KommissarAlexander 9 หลายเดือนก่อน +1

    Amazing work, I was breaking my head trying to do / find somethjng like this

  • @구영민-o8h
    @구영민-o8h 2 หลายเดือนก่อน

    THANK YOU... 감사합니다... THANK YOU... 감사합니다... THANK YOU... 감사합니다... THANK YOU... 감사합니다...

  • @sailorjune2121
    @sailorjune2121 ปีที่แล้ว

    This is why it’s important to read the docs
    I spent all yesterday trying to implement a star from scratch 💀💀💀
    Godot rules

  • @CosmoCodez
    @CosmoCodez 6 หลายเดือนก่อน

    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.

  • @timflatus
    @timflatus 10 หลายเดือนก่อน +1

    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.

  • @AndrewKwiatkowski
    @AndrewKwiatkowski ปีที่แล้ว +7

    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

  • @nyx3m
    @nyx3m ปีที่แล้ว +4

    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 🎉

  • @speggeri90
    @speggeri90 4 หลายเดือนก่อน +2

    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.

  • @constantinalexe4862
    @constantinalexe4862 4 วันที่ผ่านมา +1

    Everything works besides the section for preventing the character from entering specific tiles. I get the error "Invalid call to funtion 'get_cell_tile_data' in base TileMapLayer. Expected 1 arguments."

  • @zirklutesKerpa
    @zirklutesKerpa ปีที่แล้ว +1

    This is an amazing tutorial, thank you so much!

  • @forexdisk9693
    @forexdisk9693 3 หลายเดือนก่อน

    awesome tutorial!!!

  • @SpankyDmonkeyChannel
    @SpankyDmonkeyChannel 14 วันที่ผ่านมา +1

    For some reason on the very first move I do, my player moves towards 0,0 on the grid before continuing through the path to the target position. No matter where I place my player along the tilemap it always does this on the first move. Any idea why? All attempts to see why are failing me :\. Its like for some reason on that first move it is told to move towards 0,0 THEN to wherever the target point is.

  • @CaptmagiKono
    @CaptmagiKono ปีที่แล้ว +3

    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.

  • @dougsaylor6442
    @dougsaylor6442 11 หลายเดือนก่อน +1

    Really great video! This helped a lot. :)

  • @stinghouseproductions8502
    @stinghouseproductions8502 2 หลายเดือนก่อน

    Thanks for making this.

    • @stinghouseproductions8502
      @stinghouseproductions8502 2 หลายเดือนก่อน

      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  2 หลายเดือนก่อน +1

      @@stinghouseproductions8502 Thanks for the kind words

  • @hachetrescomacatorce2340
    @hachetrescomacatorce2340 5 หลายเดือนก่อน

    you are awesome bro, thanks!!! greetings from colombia

  • @moboy-i1z
    @moboy-i1z 10 หลายเดือนก่อน +2

    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 5 หลายเดือนก่อน

      did u solve the problem ?

  • @prechabahnglai103
    @prechabahnglai103 ปีที่แล้ว

    Been looking for this. THANK YOU SO MUCH!

  • @Hauness349
    @Hauness349 10 หลายเดือนก่อน +1

    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?

  • @plyr0
    @plyr0 10 หลายเดือนก่อน

    Great tutorial! Thank You!

  • @purplepixeleater
    @purplepixeleater ปีที่แล้ว +6

    any chance we can get a tutorial on how to do this with isometric tilemaps? Does it work the same?

    • @CptProtagonist
      @CptProtagonist 7 หลายเดือนก่อน +1

      currently testing this with an isometric map and it seems to be working the same so far

  • @ParryMime
    @ParryMime 11 หลายเดือนก่อน

    Excellent tutorial!

  • @jablao
    @jablao 10 หลายเดือนก่อน

    great video, helped me a lot, thank you

  • @ichlalsulbulqiah1974
    @ichlalsulbulqiah1974 7 หลายเดือนก่อน

    Thank you so much for your tutorial, it's really helpfull

  • @kvcs-pl
    @kvcs-pl 5 หลายเดือนก่อน

    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!

  • @Gandalf_Le_Dev
    @Gandalf_Le_Dev ปีที่แล้ว +1

    Great tutorial, thanks :D

  • @CaptmagiKono
    @CaptmagiKono ปีที่แล้ว

    Thanks, this was very helpful.

  • @adamkerr6853
    @adamkerr6853 ปีที่แล้ว +1

    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.

  • @brandonjacksoon
    @brandonjacksoon 9 หลายเดือนก่อน

    Thanks for the tutorial! Liked and subscribed!)

  • @NoRageStudios
    @NoRageStudios 10 หลายเดือนก่อน +1

    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 10 หลายเดือนก่อน +1

      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 5 หลายเดือนก่อน

      @@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 5 หลายเดือนก่อน

      ​@@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 😟

  • @AlexandroTrevisan
    @AlexandroTrevisan ปีที่แล้ว

    Nice and to the point! I like that!

  • @ubit123
    @ubit123 ปีที่แล้ว +2

    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.

  • @DrNabeel20
    @DrNabeel20 ปีที่แล้ว

    Super usful! thank you very much

  • @Dustifer
    @Dustifer 6 หลายเดือนก่อน

    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...

  • @deepfriedtuba
    @deepfriedtuba 7 หลายเดือนก่อน

    Could you make a video applying this to multiple selectable agents? Like RTS style movement

  • @FuzzballStudios
    @FuzzballStudios ปีที่แล้ว +1

    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 10 หลายเดือนก่อน

      @@ubit123 why tho

  • @abdou023
    @abdou023 7 หลายเดือนก่อน

    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.

  • @spiritnet6219
    @spiritnet6219 ปีที่แล้ว

    Hi, very interresting implementation.Just one question plz: how do you manage obstacle ?

  • @CutyDina
    @CutyDina 9 หลายเดือนก่อน

    love this tutorial! is there a way to keep moving until it crashes with any obstacle? like sliding?

  • @StandAlone3
    @StandAlone3 9 หลายเดือนก่อน +1

    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.

    • @SpankyDmonkeyChannel
      @SpankyDmonkeyChannel 14 วันที่ผ่านมา

      Hey I'm running into this issue too. Did you ever happen to fix it?

  • @longuemire748
    @longuemire748 ปีที่แล้ว +5

    Thanks for this tutorial,
    Does it also work for isometric?

    • @RetroBright262
      @RetroBright262  ปีที่แล้ว +6

      Isometric tile maps require a separate implementation; expect a video soon. 🙂

    • @longuemire748
      @longuemire748 ปีที่แล้ว

      @@RetroBright262 Thank you :), The code is very intuitive.

    • @JoksterStudios
      @JoksterStudios ปีที่แล้ว +1

      great tutorial - just followed it on an isometic tileset and worked like a charm except the final path drawing@@RetroBright262

    • @Voxet1
      @Voxet1 11 หลายเดือนก่อน

      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 5 หลายเดือนก่อน

      @@RetroBright262 can u make an animation guide for this tybe of movement plz i need it so bad

  • @thecumscrubber
    @thecumscrubber 6 หลายเดือนก่อน

    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!

  • @A_Veget4ble
    @A_Veget4ble 6 หลายเดือนก่อน +1

    Hello I really appreciate the tutorial, but do you know how to add a limit to how far the player can travel?

    • @palatonian9618
      @palatonian9618 หลายเดือนก่อน

      I think the limit should be inherent to the astargrid you create?

  • @palatonian9618
    @palatonian9618 หลายเดือนก่อน

    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

  • @MrHsktoto
    @MrHsktoto 10 หลายเดือนก่อน

    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 ?

  • @NomarOmens
    @NomarOmens 11 หลายเดือนก่อน +1

    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 5 หลายเดือนก่อน

      Mine walks right through them too

  • @andresgrimminck8674
    @andresgrimminck8674 7 หลายเดือนก่อน

    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?

  • @hamtown4757
    @hamtown4757 6 หลายเดือนก่อน

    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.

  • @ArgonZavious
    @ArgonZavious 11 หลายเดือนก่อน

    Thank you!

  • @ReddleyYT
    @ReddleyYT 10 หลายเดือนก่อน

    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 10 หลายเดือนก่อน

      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

  • @papierk0rp
    @papierk0rp ปีที่แล้ว

    This was really helpfull thanks a lot.

  • @Lets_Get_This_Bread
    @Lets_Get_This_Bread 9 หลายเดือนก่อน

    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

  • @IVThesimple3436
    @IVThesimple3436 6 หลายเดือนก่อน

    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 5 หลายเดือนก่อน

      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

  • @cr0wmatic
    @cr0wmatic ปีที่แล้ว

    would anything change when using a hex tilemap instead of a square tilemap?

  • @AzaIndustries
    @AzaIndustries 11 วันที่ผ่านมา

    huh... I got most of it working but my map_to_local always returns 0, 0. No matter what vector2i I feed it.
    Edit: found a workaround. Great tutorial.

  • @Drachenbauer
    @Drachenbauer 10 หลายเดือนก่อน

    the player sprite should better be an extra graphic with transparent background to prevent vovering grass-pattern outside the actual character´s body.

  • @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

  • @JD-us8xw
    @JD-us8xw 6 หลายเดือนก่อน

    Is there a way to adapt this to run on multiple tilemaps?

  • @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  ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      Make updating the collision info on the map part of the movement function!

    • @martin-gaming
      @martin-gaming ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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

  • @agam3z153
    @agam3z153 5 หลายเดือนก่อน +2

    14:56 i but " , " after y and it worked
    great tutorial btw 🤍
    can u make tutorial about animations in this style of movement ?

  • @TheIronicRaven
    @TheIronicRaven ปีที่แล้ว

    Any chance you would make this for 3D? For GridMap?

  • @guuiswere
    @guuiswere 3 หลายเดือนก่อน

  • @sajberkg
    @sajberkg 7 หลายเดือนก่อน

    is the code available somewhere? :)

  • @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.

  • @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

  • @puleroxd4116
    @puleroxd4116 7 หลายเดือนก่อน +1

    My code says invalid operands Vector2 and Vector2i in operator ==. I only managed to do the tutorial until 10:13

    • @puleroxd4116
      @puleroxd4116 7 หลายเดือนก่อน +1

      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

  • @bizidru
    @bizidru ปีที่แล้ว

    why didn't you want to use it Line2D? It's much easier to use line drawing

  • @peace__duke
    @peace__duke 6 หลายเดือนก่อน

    source code pls

  • @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 ปีที่แล้ว +1

      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 ปีที่แล้ว

      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ы 5 หลายเดือนก่อน

    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