Because of the problems I mentioned I cannot use proccess, so the Raycast2D didn't help.
I tried different things and the only way I found to get an acceptable result was the above function which runs every time 3 tiles match:
func tile_shift():
var fpos=first_tile.global_position
var spos=sec_tile.global_position
var tpos=third_tile.global_position
for fruit in $Fruits.get_children():
#if fpos.x != spos.x and spos.x != tpos.x:
if fruit.global_position.x == fpos.x and fruit.global_position.y < fpos.y:
fruit.global_position = Vector2(fruit.global_position.x, fruit.global_position.y + step)
if fruit.global_position.x == spos.x and fruit.global_position.y < spos.y:
fruit.global_position = Vector2(fruit.global_position.x, fruit.global_position.y + step)
if fruit.global_position.x == tpos.x and fruit.global_position.y < tpos.y:
fruit.global_position = Vector2(fruit.global_position.x, fruit.global_position.y + step)
The above function basically works but there are 2 problems.
1. When the 3 tiles are the one below the other:
A
B
C
Then the tile(or tiles) above them which need to move, move by 1 step, so there is an empty space
2. When 2 tiles are one below the other and the 3rd is in a different place. For example:
-A --------------------- A
-B ---------or ------------- B
------ C -------------------- C
Then again works but need an adjustment by about ~ +10pixels for the tile which is above those 2 tiles.
I tried to solve this with some different ways but I always end to make it worst.
So, any ideas or help to improve the function to include those cases?