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.
0 votes

Short: Is there a way to center navigation2d points to tilemap tiles?

In an attempt of using tilmap with navpoly for tilebased movement, I tried centering the navigation points (there is a thread about this around here somewhere, although I can't find it) like so:

#Calculate path from player/start position to a clicked position:
var clickpos = get_global_mouse_pos()
path =Array(nav.get_simple_path(player.get_global_pos(),clickpos,true))

#Store centered points in the array "centerpath":
for p in path:
    var centerpoint =map.map_to_world(map.world_to_map(p)) +Vector2(0,map.get_cell_size().y/2.0)

#Use "centerpath" as actual navigation path:

This will center the path's points (white dots) but also result in some problems:
green = walkable, gray = not walkable, red = Start & Click positions

I guess this is because navigation2d adds its points like this:

Replacing bits of the code in order to get the relevant 'walkable' tiles:

for p in path:
    var tile= map.world_to_map(p)   #Get tileset coordinates at p.
    var tilepoint =map.map_to_world((tile)) #Get current tile's "global" coordinates.

...returns point 5 of 7 (in the example above) as a gray tile. Shouldn't this only return coordinates from 'walkable' tiles, since it was taken from navigation2d's path array in the first place?

The problem persists on square tilemaps and does not only allow cutting corners, but also stopping and traversing over some gray or empty tiles like this.

Is there a way of getting around this?

in Engine by (46 points)
edited by

I ran in the same kind of problems and others more while trying to incorporate Godot's A* on my projects, So I did my own. It's really simple and you gain a lot more control over the way you want it to work. Would you consider it? This site has all you can possibly need for it, and I can provide my old project for you to mess around if you want.

I had no such problems with the A* node. It actually worked really well. Problem is that using more than a handfull of tiles makes the initial calculations horribly slow. I'm not competent enough to tell whether this is a general A* thing or if the godot node is to blame. My implementation was semi-based on this demo project btw.
Having said that, I would love to mess around with your old project (that is, unless it has a broken A* that I could never hope to fix).

Oh, and thanks for the tip. Great read!

Idk either, but in my experience the Godot's navigation and A* were always a hassle to adapt; more code went in corrections than in features... So making one is really much more efficient. My project is also isometric, so it'll probably be easier to see the advantages this can potentially bring to your game.

Give it a try!

Looks really promising! I'm going to mess around and see what it can do. A little confused by the double tilemap nodes... :)

Wops, looks like I should have cleaned that. It's because the original ideia was making maps with multiple heights (tilemaps), so one would be for aesthetics and the other would be for actual navigation data.
However I couldn't get around the way the tilemap Y-sorting worked, so I just left it as it was. But you can easily define what is a valid tile and what isn't by index from a single tilemap in code and getting rid off the nav tilemap.

Got it working pretty smoothly with a single tilemap and diagonal movement. Tweaked a few things to make it work with different tile sizes.
Seriously, this is pretty darn good! You should clean it up a little bit and put it in the asset library, if it's not already in there.

Yeah, maybe I should do it... Well, anyway, glad you liked it. Good luck on your project!

And good luck with your stuff as well!

Please log in or register to answer this question.

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.