Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | scrubswithnosleeves |
Hey All,
So I am using noise textures and a TileMap
to generate random levels. black becomes collision tiles, white becomes empty tiles with navigation. Then I call the Navigation2DServer
to get a path from the start to end point. ( I use the tilemap’s method update_dirty_quadrants()
before the nav)
Completely randomly, the server will just return an empty path, even though there is clearly a reachable path. And if I re-run the TileMap
generation and run it again within the same session, it fails again. In my code this creates a stack overflow and crashes.
Sometimes I have to run the script 20 times before it fails. Sometimes it happens twice in a row. Any ideas?
The code is pretty long, but Ill include the abridged version below:
noise = OpenSimplexNoise.new()
noise.seed = randi()
noise.octaves = 1
noise.period = 5.5
for x in range(1, ROOM_SIZE.x):
for y in range(ROOM_SIZE.y+1):
var id = gen_id(noise.get_noise_2d(x, y)) # returns 0 or 1 depending on value
set_cell(x, y, id)
update_dirty_quadrants()
var map = Navigation2DServer.get_maps()[0]
Navigation2DServer.map_force_update(map) # fails without this line
var path = Navigation2DServer.map_get_path(map, start_pos, end_pos, true)
This is a hard one to test but…
for x in range(1, ROOM_SIZE.x):
for y in range(ROOM_SIZE.y+1):
This looks suspect to me. Are you intentionally skipping all the tiles in the first column range(1, ROOM_SIZE.x)
?
Also are you intentionally including tiles outside the y boundary range(ROOM_SIZE.y+1)
?
LeslieS | 2023-01-09 01:12