Should make working with tilemaps and navpolys much less annoying.
extends Navigation2D
var tmap = null
var size_vector = Vector2(2000,2000)
var walk_tile = 0
var blocked_tile = 1
var invisible_blocked_tile = 3
func _ready():
tmap = get_node("TileMap")
fill_tilemap() # change empty tiles to invisible tile with just navigation poly
delete_squares() # remove nav tiles near the walls
remove_child(tmap) # readd tilemap, otherwise navigation poly wont work
add_child(tmap)
func fill_tilemap():
var tset = tmap.get_tileset()
var end = tmap.world_to_map(size_vector)
for x in range(end.x):
for y in range(end.y):
if tmap.get_cell(x,y) == -1:
tmap.set_cell(x,y, walk_tile)
func delete_squares():
var end = tmap.world_to_map(size_vector)
for x in range(end.x):
for y in range(end.y):
if tmap.get_cell(x,y) == blocked_tile:
tmap.set_cell(x,y, invisible_blocked_tile)
# below this is optional, creates buffers around walls
for xx in [-1,0,1]:
for yy in [-1,0,1]:
if xx == 0 and yy == 0:
continue
if tmap.get_cell(x+xx,y+yy) == 0:
tmap.set_cell(x+xx,y+yy, invisible_blocked_tile)
Should make working with tilemaps and navpolys much less annoying.