0 votes

I'm creating top down game with tile based movement, and I want to add the possibility to move to a position by clicking the mouse button. To do so, I created a function which take an array of directions and follow the path.

I'm using the Navigation2D node to make the pathfinding (I added the tilemap as a child of the Navigation2D) and get the position array, but the points doesn't seems to be correct.

Here is an example:
enter image description here

I'm using this simple function:
var points = navigation.get_simple_path(position, destination, false)

If I click on the marked tile, here is what points contains :enter image description here

With a tile size of 32px, I don't understand why each position is incremented by 16px.

Also if I click on the tile just to the right of this one, here is what I get :enter image description here

It seems to make a diagonal movement, but it's probably intented ?

Finally, here is how I created the NavigationPolygonInstance in the Tileset, because it may be related to this :
enter image description here

I think I don't understand how the Navigation2D works, what am I doing wrong ?

asked Jul 5, 2017 in Engine by Majesty (17 points)
edited Jul 5, 2017 by Majesty

Only need change false to true:

var points = navigation.get_simple_path(position, destination, true)

1 Answer

+1 vote
answered Jul 10, 2017 by NVA_Lee22 (42 points)
edited Jul 14, 2017 by NVA_Lee22

In this video you can see demonstration of above mentioned approach:
https://www.youtube.com/watch?v=KU1PslMiZ98

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 How to use this Q&A? before posting your first questions.