Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

Thanks for the feedback.


For pathfinding:

At first I had tried to use a `NavigationAgent2D` and a `TileSet` navigation layer, but eventually gave up on it due to getting caught on corners. Since I had already added navigation polygons to the floor tiles I ended up walking the `TileMap.get_used_rect`, checking the `get_cell_tile_data(0,coordinate).get_navigation_polygon(0)`.  Then I build an `AStarGrid2D` with `set_point_solid(id,true)`. Then the `get_*_path` methods did the hard work.  Enemies end up trying to walk in the center of the tiles most of the time, but it's still possible to get them stuck on corners, or if two enemies have opposite paths they get can get stuck on each other.

There is a bit of fun using `TileMap.get_used_rect().position` as the offset difference between a `TileMap` coordinate and an `AStarGrid2D` id. Conversions are also required to global space for moving, or converting screen space to coordinates for mouse clicks.  Not sure I have the screen -> coordinate 100%, but it works in the current camera/viewport setup.

The skeletons also use a `RayCast2D` to the player and check for wall/pit collisions to act like a line of sight mechanic and only recalculate their target path if they can see the player.

When the tile changes due to a user action it also updates the `AStar2DGrid` and enemies recalculate the path to take.

Thank you so much for taking the time to explain all of that!

Interesting! I've used the Naviation2D with TileSet navigation layer before, but I think it was somewhat limited and was curious what other approaches there are for pathfinding in Godot. 

Cool stuff!