This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+6 votes

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!

in Engine by (381 points)

3 Answers

+5 votes


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.

by (76 points)
+6 votes

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.

by (140 points)

Not applicable in Godot 4 as the API has changed

+1 vote

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.

by (283 points)
edited by

I love this one, thank you!

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.