Skip to content
Player controller and pathfinding

Player controller and pathfinding

May 16, 2026

Player character scene

I set up the basic CharacterBody2D player scene with a CollisionShape2D, a placeholder AnimatedSprite2D, and added it to the main scene.

Pathfinding

This part became interesting when I first tried using an A* approach with AStar2D for grid-based pathfinding. AStar2D is designed for shortest-path search on a connected graph, which makes it a solid fit for grid movement, but not always for more organic navigation.

After a few experiments, I dropped that idea because I needed something more flexible than grid-based movement. The character was moving on a grid, and smoothing the path did not improve the experience enough.

I eventually found that NavigationServer2D was a better match for what I wanted. Godot’s navigation system is built around navigable regions and NavigationRegion2D, which can be used together with NavigationAgent2D for pathfinding and path following.

Generated navigation

The navigation polygon is generated programmatically because the dungeon map will be created procedurally when the player enters the area. After that, the NavigationRegion2D can bake the navigation polygon, which is exactly the kind of workflow Godot supports for dynamic navigation regions.

Using polygons for navigation works well here because the map has simple shapes and the generation cost stays manageable. That also avoids the limitations I ran into with grid movement and gives a much smoother result than my first attempt.

The result is very satisfying, the character no longer gets stuck on walls, and clicking in different directions does not break the movement flow:

Last updated on