https://github.com/Drachenbauer/Sokoban
This is a Sokoban-geme, that I create on Godot.
Now the player can push a box once, but than nomore reactions on the input-keys.
The player and the box both call this function from the level:
func update_child_pos(child_node):
var grid_pos = world_to_map(child_node.position)
grid[grid_pos.x][grid_pos.y] = null
var new_grid_pos = grid_pos + child_node.direction
grid[new_grid_pos.x][new_grid_pos.y] = child_node.type
var target_pos = map_to_world(new_grid_pos)
return target_pos
the grid-array stores empty values or the type of wall, player or box in it´s cells
I think, the bug comes, because the player calls the function a tiny little bit earlyer, than the box.
the player overwrites the box on it´s new position.
and while the box calls the function, it overwrites the player on it´s now reached position with null.
The result: no more cell of the grid-araay is marked with the type of the player, who now has no more reference-position to calculate it´s movement
both call the function in physicsprocess(delta).
How can i control, that the box executes the process first and than the player?
I added processpriority = 9 in _ready() of the box and
processpriority = 10 at the player.
But it makes no difference
Now i surrounded the line, that empties a cell in the array with an if:
var is_player_already_on_box_pos = child_node.type == BOX && grid[grid_pos.x][grid_pos.y] == PLAYER
if !is_player_already_on_box_pos:
grid[grid_pos.x][grid_pos.y] = null
this works in the game, put the
func has_pusher(pos, direction):
var pusher_pos = world_to_map(pos)
return grid[pusher_pos.x][pusher_pos.y] == PLAYER
still looks wrong, because the grid-cell, where the box actually is, is already marked with the player, when this function is called.
so i really want all boxes execute their physics-process before the player.
or can i somehow replace the box´s physicsprocess with a custom function (it includes moveandcollide(velocity)) and call it at the beginning of the player`s physicsprocess?