pos == the position of the ball that hits the brick
dir == the direction of the ball normalized.
So we hit the tileset get via a signal the position of the ball. I convert to worldtomap() to get the tile position. However the ball position is never the collided tile.
Value that is passed when ball collides with brick.
func _physics_process(delta):
var bodies = get_colliding_bodies()
for body in bodies:
if body.get_name() == 'bricks':
emit_signal("hit", position, linear_velocity.normalized())
World map tileset script
func _collided(pos, dir):
for child in get_children():
if child.get_name() == "bricks":
print(pos)
if dir.x <= 0:
pos.x = pos.x + 16
else:
pos.x = pos.x - 16
if dir.y <= 0:
pos.y = pos.y + 8
else:
pos.y = pos.y - 8
print(pos)
var tile = child.world_to_map(pos)
print(child.get_used_cells())
print(tile)
child.set_cellv(tile, -1)