I’m making a top-down game where the player can drag the characters on the screen, and I’m wondering how I should avoid the player from dragging a character into another one.
I’ve tried this code that was run every frame for the character that was being dragged to get that character out of the other hitboxes :
if distance_keeping:
while $BigHitbox.get_overlapping_areas():
for i in $BigHitbox.get_overlapping_areas():
position += (position - i.get_parent().position).normalized()
However, as it turns out, get_overlapping_areas only updates each physics step, so it gets stuck in an infinite loop and I didn’t find any way to manually update the collisions.
I’ve thought about somehow calculating how much the character should move in order to get out of the other character’s hitbox, but even if I did that, moving out of a character’s hitbox can easily cause to move into another character’s hitbox, and I still wouldn’t know about it because get_overlapping_areas wouldn’t update till the next physics update.
I’ve also thought about applying phyisics to the characters and use move_and_slide in the direction where the mouse is moved but then it wouldn’t go through characters at all – even after it could without it ending up in another hitbox.