Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | IHate |
I want to trace a line concealed within tracks with the mouse its the same mechanic that The Witness for its puzzles: https://youtu.be/bNEhkcPOcpM?t=47.
My tracks are procedurally generated using a tilemap.
Ideally I would have a line 2d and be able to extend it between the tiles.
The best I got is using event.relative and adding a tile on the direction with more “strenght” but this creates a tile every time you move a single pixel so its hard to control and visually it’s pretty choppy in comparison with how a line2d would look like.
var tiles
func _ready():
tiles = map.get_used_cells()
func _input(event):
if event is InputEventMouseMotion:
var tile_pos = map.world_to_map(position)
var dir
if abs(event.relative.x) > abs(event.relative.y):
if event.relative.x > 0:
dir = Vector2.RIGHT
else:
dir = Vector2.LEFT
else:
if event.relative.y > 0:
dir = Vector2.DOWN
else:
dir = Vector2.UP
if not tiles.has(curr_tile + dir):
return
curr_tile += dir
set_cellv(curr_tile,0)
route.append(curr_tile)