Navigation doesn't choose shortest route

Godot Version

v4.2.2.stable.official [15073afe3]



I’m developing a turn-based combat game with movement reminiscent of typical turn-based combat games (eg. Baldur’s Gate 3). I’m currently struggling with unit movement and a problem I’ve tried to tackle for a couple of days. I’m posting a drawing I threw together since I believe it should correctly demonstrate my problem, but I can produce code snippets upon demand as well.

I’ve tried cropping the path based on eg. LOS raycasting, but that doesn’t really solve the problem as I’d need to consider eg. the number and direction of the points leading up to the target. I feel I need a more robust solution to this problem.

I’ve also tried tweaking navigation mesh parameters, such as error margins and cell sizes, but that hasn’t really helped either. Furthermore, retrieving the path using NavigationPathQueryParameters3D.query_path doesn’t really help as the parameters i’m using results in the same path as using map_get_path.

I’m fairly new to Godot but I have spent a substantial amount of spare time in Unity. I’m acquainted with how navigation works in Unity, and have implemented such a system before, since Unity may provide the path with respect to obstacles, unlike Godot.

Edit: Apologies for the shitty resolution. I could probably have upscaled it, but it should at least be readable

Update: I also posted on Reddit, where I was adviced to expand upon the raycasting approach, but to raycast from every point in the path generated by the navigation server. I guess this’d require me to design a potentially recursive function for traversing the path and continuously re-evaluating it before finally returning it to the player.

This sort of raises further questions on my end on whether I’m missing some best practices on how to design turn-based navigation in Godot.