0 votes

Disclaimer: I'm a Godot beginner and this is probably obvious.

I'm trying to make a very simple 2D pathfinding exercise using:
- a Navigation2D node,
- a TileMap node using a tileset edited via the new Godot 3.1 editor, where one single tile is created/declared with a full rectangular NavigationPolygon over it (this tile covers the whole map),
- a simple KineticBody2D object (containing a Sprite and CollisionShape2D) that I'd like to move around within that map.

I'm using the code from recent GDQuest tutorials, which simply waits for mouse clicks, calls Navigation2D.get_simple_path to fetch the path toward the click, then moves the object along it.

My Issue

When moving the object in a "long" diagonal, get_simple_path will return 3 or more points instead of 2 and the object will therefore move in two or more unnatural steps towards its target.

Is there any reason for this? I've followed other tutorials where this didn't happen, using "manual" NavigationPolygonInstance. I cannot figure out any other difference.

Demo (minimal) project

https://drive.google.com/uc?authuser=0&id=17UlmKSQfDDFbsD2OMVcVsevz-SbfUYwd&export=download


in Engine by (15 points)

2 Answers

+1 vote
Best answer

Edit: https://github.com/godotengine/godot/issues/28235

------------- original answer ---------------

The title of this question should be "Navigation with Tilemap has never heard about Pythagorean theorem" :D

The truth is, i dont know.

I tried your project and i dont see anything wrong (well, nitpicking, you ignore the fact that get_simple_path is returning points relative to navigation2d node, so you should offset them to your tank space -- but in your case, you dont have to, navigation offset to common parent with your tank is [0;0])

I recreated your project from scratch and have exactly the same problem:

Godot 3.1.0
same_result

(you can download it here)

Godot 3.0.6
stuill_not_much

Better but still not clean path
You can download this project here

by (233 points)
edited by

@splite Thank you very much for looking into this!

I actually spoke with KidsCanCode on Discord, who's the guy who made this tutorial. I've downloaded its source here from GitHub and opened the corresponding project, tiled the middle part of the map (there were some "holes") and hit F5 to get the exact same kind of result:

https://streamable.com/47nzc

Now if instead of using per-tile navigation polygons, I replace it with a single NavigationPolygonInstance covering the whole navigable space, it behaves just fine:

https://streamable.com/exk7u

(KidsCanCode told me he was curious and suspected a bug as well, and would take a look when he finds the time.)

Note that that project isn't using the new Godot 3.1 Tileset editor at all, so it isn't related to it.

I'm tempted to open an issue on the official GitHub and see what the Godot people tell me there. Do you think that would be appropriate?

Yes, of course, they are nice guys + good thing is, you did your reserach first (you asked here). This is a great preparation for opening a issue.

https://github.com/godotengine/godot/issues/new

Try to make things clear & give them your minimal project (the one you posted here is great - btw, you can just drag&drop file to github issue), link this question (or send there link to your issue, i will repost my gifs :) )

Just did: https://github.com/godotengine/godot/issues/28235

I took the liberty to use one of your nice animated gifs :)

Thanks again!

Ok, i was thinking, maybe we are doing it wrong - maybe you are supposed to have own NavigationPolygon and what you paint on your tiles is like "DO NOT WALK THERE" polys (so your walkable location is XOR between big NavigationPoly and small polys from tiles...

Or throw away the big NavigationPoly entirely - and you are walking "outside" of the tile navi polys.

Either way, what you paint on tileset is "do not walk here". And if thats true, Godot team did a poor job telegraphing the idea.

Cant test it right now (dont have any free time :( )

Edit: well, i tested it and nope, doesnt work at all

Lets wait what guys say officially at your issue (worst case scenario is they tell us how to do it properly :) )

By the way, for capturing gif, i am using https://www.screentogif.com/

0 votes

The problem with Godot's navigation system is, it goes in any direction over the tilemaps. If you have a game where you want the path to go straight or diagonal over the tilemap, you have to write the algorithm either yourself or use something like SmartTilemap2D

by (21 points)
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.
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 webmaster@godotengine.org with your username.