I'm doing grid-based movement in my 2d game, but I want characters to be able to stack in a single tile to a certain point. I'm trying to figure out a movement solution that would allow me to do this.
My current idea is having characters have an Area2d for their collision and when moving to a new tile, they have a second small 'checker' Area2d that is unmonitorable. When a character wants to move, it throws its checker to the position is wants to move and checks for collisions at that point. If there's a wall or more than 5 area2ds in that tile, it won't be able to move there.
get_overlapping_areas() doesn't seem to update fast enough for my function and using signals haven't worked either. Also, detecting collision bodies for walls just haven't worked at all. I do have my layer masks set up so the checker should be able to see the walls.
For the get_overlapping_areas(), I'm guessing I'm trying to use it too fast? I have no idea for get_overlapping_bodies() which doesn't trigger at all. Relevant code:
func _physics_process(_delta) -> void:
var target_pos = get_viewport().get_mouse_position()
var checked = check_move(target_pos)
if checked != position:
global_position = checked
func check_move(pos : Vector2) -> Vector2:
var snapped_pos = Grid.snap_pos_to_grid(pos)
$Checker.global_position = snapped_pos
if $Checker.overlapping_bodies.size() > 0:
print("%s areas detected here!!" % $Checker.overlapping_areas.size())
checker.gd (this is where the variables from $Checker from above come from)
var overlapping_areas : Array
var overlapping_bodies : Array
overlapping_areas = get_overlapping_areas()
overlapping_bodies = get_overlapping_bodies()