Alcadur
Alcadur

Reputation: 685

Navigation2D always return empty path

I have a tile map with 16 tiles like:

enter image description here

each tile have defined navigation (as big as possible):

enter image description here

but Navigation2D in most time return an empty array when I click on a tile

The code can be found on Github: link to repo

Upvotes: 3

Views: 1509

Answers (1)

Theraot
Theraot

Reputation: 40295

As you might be aware, in the Debug menu in the editor, there are options "Visible Collision Shapes" and "Visible Navigation". Enable them, and play the game.

It will show you, as the names of the options suggest, the collision and navigation shapes. You want to make sure that:

  • The tile navigation stays inside the tiles.
  • The tile navigation does not overlap the tile collision.
  • The tile navigation does not overlap itself.
  • There are no gaps between tile navigation of adjacent tiles.

If you see any of these problem, redo the navigation shape for the problematic tiles. Some advice:

  • Snapping: When editing the navigation of a tile, Click the "Enable snap and show grid" icon. On the Inspector panel, you will find "Snap Options" set the step to something that works for you. Your tiles are 44x44, so steps of 4 work well, 11 also work well.
  • Also click "Keep polygon inside region Rect".
  • Do not start your navigation shape on the edge. This is very odd, but I have found that if I start on the edge, it will result in a self overlapping navigation (which I notice using "Visible Navigation" mentioned above).

A gap between navigation and collision is ok.

Also, remember to edit the TileSet of your TileMap. If you are editing a TileSet independently, you may have to set it to the TileMap again. Having the Debug options mentioned above, should suffice to notice if it didn't update.

And yes, I downloaded the code from the linked repository, and managed to make it work. Other things I did, but I believe are not important: I made sure there was no repeated points in the navigation shapes (if you find you have to click twice to make the dot appear while editing, you are probably making a repeated point, just click the next position instead). I also moved the collision shape to be centered in the Player.

Upvotes: 3

Related Questions