Navigation 2D using tiles to do Pathfinding, issue with corners and turns in navmesh.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By The_Black_Chess_King

Just as a landmark for this question, using Godot 3.0 stable release.

In short: The pathfinding from navigation2D does not take into account the size of the object or sprite.

Long Story: Pathfinding is a rather important subject in many games, where a unit needs to know how to move from point A to point B, while this "knowing the path" be a pathfinding algorithm, I was implementing a path finding system for my game, a isometric top down angled type, but found a serious problem while working with Navigation2D.

I am working with a tilemap, and just by starting the project found this issue, my tilemap uses tiles with navmesh data, all align and okay to be used in the built method, get simple path ().

This image I found was someone else tackling the same issue two years ago, being the first screenshot what is happenning and the second one, what was expected:

Also was discussed in this post of github, but without a solution after so much time?

I consider pathfinding to be a core element of many games, is there a fix for this problem? A simple input value to make pathfinding take into account the size of the sprite or collision shape?

Thank you in advance for the help, and for your time reading it!

:bust_in_silhouette: Reply From: ddabrahim

Hi.

I have the very same problem. I got pathfinding working in my project but navigation does not take in to account the size of the sprite and as the sprite navigate around it is overlap the edge and corners of the obstacles as shown on the image in the first post.

enter image description here

The OP posted the question almost a year ago. Is there any solution to this, any work around?

I would appreciate any help.
Thanks.

:bust_in_silhouette: Reply From: TheThirdPerson

I had the same problem and solved it by setting false on the optimization parameter of get_simple_path().

So, like this:

path = $Navigation2D.get_simple_path(origin, destination, false)

This removes the smoothing on the corners that is causing the sprites to clip into colliding bodies.

Not applicable in Godot 4 as the API has changed

sirdorius | 2022-11-05 17:09

:bust_in_silhouette: Reply From: ichster

The way I solved this issue with a KinematicBody2D is by after moving the unit a bit on the simple path, I ask it to collide in a Vector2(0.0, 0.0) direction so that the engine thread takes care of clipping. For example:

this.position = last_point.linear_interpolation( next_point, some_amount )
move_and_slide( Vector2( 0.0, 0.0 ) )

This is a bit hacky feeling, but it is easy to do and looks believable to me.

I love this one, thank you!

Zedespook | 2020-04-12 17:23

edit: changed move_and_collide( Vector2( 0.0, 0.0 ) ) to move_and_slide( Vector2( 0.0, 0.0 ) ) because otherwise you can’t get slide collision info. It also makes it a bit smoother when moving.

ichster | 2020-04-13 17:12