I seem to have a bit of problem. Creating a breakout game.
I create my bricks with a tilemap. I detect when the ball hits a brick. However the ball hits always just one tile wrong. This depending the impact of my ball on the tile.

Imagine my ball hits tile (8,5) then the debug print say I hit will be (8,6)
If I hit the brick from the top the printout says (8,4)
if I hit from the left side it will be (7,4) and right (9,4)

I have be thinking to get the direction of my ball and simple do calculate calculate the number. But that seems overkill. Is there a way not to give the tile with that the ball hits instead of the position of where the ball hits

in Engine

Can you provide your project file? I need to see the problem...

by (840 points)

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)
``````