![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Blissful |
Hey everyone! First time asking a question, so I hope it will be clear.
In a grid based game, I want to show the player the potential distance they can move.
But I am having difficulty with the diagonal tiles.
Basically I have a navigation map, and child to modulate the tiles the player can move to. In the below example you can see what I get when I allow the player one tile of movement:
The code in this regard, is just this:
func show_traversible_tiles():
var tile_pos = world_to_map(player.position)
var tile_id = get_cellv(tile_pos)
var move_distance = 1
for steps in move_distance+1:
navigation_overlay.set_cell(tile_pos.x+steps, tile_pos.y, tile_id)
navigation_overlay.set_cell(tile_pos.x-steps, tile_pos.y, tile_id)
navigation_overlay.set_cell(tile_pos.x, tile_pos.y+steps, tile_id)
navigation_overlay.set_cell(tile_pos.x, tile_pos.y-steps, tile_id)
next up is one step further of potential movement
With this code (which is probably incredibly wrong):
func show_traversible_tiles():
var tile_pos = world_to_map(player.position)
var tile_id = get_cellv(tile_pos)
var move_distance = 2
for steps in move_distance+1:
navigation_overlay.set_cell(tile_pos.x+steps, tile_pos.y, tile_id)
navigation_overlay.set_cell(tile_pos.x-steps, tile_pos.y, tile_id)
navigation_overlay.set_cell(tile_pos.x, tile_pos.y+steps, tile_id)
navigation_overlay.set_cell(tile_pos.x, tile_pos.y-steps, tile_id)
navigation_overlay.set_cell(tile_pos.x+int(steps/2), tile_pos.y+int(steps/2), tile_id)
navigation_overlay.set_cell(tile_pos.x-int(steps/2), tile_pos.y-int(steps/2), tile_id)
navigation_overlay.set_cell(tile_pos.x+int(steps/2), tile_pos.y-int(steps/2), tile_id)
navigation_overlay.set_cell(tile_pos.x-int(steps/2), tile_pos.y+int(steps/2), tile_id)
But it just completely breaks down after this.
I’m having a hard time figuring out how to cleanly write this and make it scale. So that it works at every distance.