I am learning about navigation and have set up my tileset to have the floor tiles marked as navigable as seen by the highlighted tiles during debug gameplay. As my enemy entity starting in the corridor I have a simple node (denoted by _self) with the following code running when I press a key:
_navigationAgent.TargetPosition = _player.Position;
if (_navigationAgent.IsNavigationFinished()) return;
var direction = _self.Position.DirectionTo(_navigationAgent.GetNextPathPosition());
_self.Position = (_self.Position + direction * TileSize).Snapped(Vector2.One * TileSize);
What's noticeable is that the computed path by Godot clips through the non-navigable wall and cuts diagonally at times. For the time being I have the following questions:
- How can I adjust the behavior of the path finding to not take the paths through walls? Are there parameters to ensure this behavior or do I have setup my own instance of the AstarGrid2D algorithm? If possible I'd like to use most of the out of the box features where possible.
- For the beginning I want to disallow diagonal movement which probably means having to change the heuristic of the algorithm. Can this be achieved with the built-in NavigationAgent2D node?
- Once everything works as expected I'd like to allow diagonal movement only if it doesn't cut corners. I can imagine this will require some more custom code to alter the path finding behavior.