DevLog: Fixing Invalid Click Locations in Pathfinding - Keegen Love


This week, I ran into a frustrating issue with handling invalid click locations in our game. The core problem was that the NavMesh system was struggling to properly handle pathfinding requests to locations that weren't valid—like when a player clicked somewhere offscreen, inside an impassable object, or outside the playable area. The result? The game would ignore the player’s command without providing any feedback, which made the gameplay feel unintuitive. Players got frustrated when their units failed to respond to valid commands simply because of slight miscalculations in pathfinding, such as clipping through terrain or models that shouldn't be passed through. While the issue didn’t cause any major delays, it did push our system release closer to the deadline, as I had to prioritize addressing this problem.

The root cause of the issue was how the our system handled path projection. Even a small vertical shift in the click location—something that happens more often than you’d expect—could cause the pathfinding algorithm to fail. It would try to draw a straight line from the player's location to the clicked point, and if there was even a slight clip with the ground or objects, the path was deemed invalid. This caused units to fail to respond, even when the destination was perfectly navigable.

Showcased in red/green are the old paths the system "sees".

To fix this, I adjusted the pathfinding algorithm to account for these situations, depending instead on looser queries to NavMesh. Instead of just projecting a straight line, the system now checks for more nuanced path validity. It considers the surrounding terrain and obstacles, ensuring that small vertical shifts or obstructions don’t result in an invalid response. This change has made the game feel a lot more responsive and intuitive. Invalid selections are now properly culled, so players won’t end up clicking offscreen or into walls with no feedback.

Showcased in green are the new paths the system "sees".
With this fix, the game’s mechanics feel smoother, and there are fewer situations  where the game seems to behave in ways that make the players interactions with it feel ignored. The game is now more forgiving of small mistakes, reducing bugs and improving the overall experience. Moving forward, my next step will be to add further action culling, like action canceling, to make sure commands are executed appropriately. Right now, once a command is issued, it’s followed through to the end, regardless of changes in the game environment. By refining this system, I hope to improve future playtesting and player interaction.

Get Return to Divinity

Leave a comment

Log in with itch.io to leave a comment.