Topic was automatically imported from the old Question2Answer platform.
Asked By
Roadkill
Im working on a game with two playable characters at once. To complete each level I want for both characters to be present at the same time at the end of the level. For this Im using an area2D which uses get_overlapping_bodies() and goes through that array to check if its colliding with both player characters (both of which are kinematic bodies)
It works when I check for only one of the characters but I cannot figure out how to require both characters colliding with the Area2D at once to change scenes.
Is this way wrong or is this there an easier way to go about this maybe?
If the Area2D can only collide with your players simply check get_overlapping_bodies().size() > 1 inside of _physics_process() or _process(). Otherwise do something like this:
player_one_in_area = false
player_two_in_area = false
for body in get_overlapping_bodies():
if body [some check that guarantees player one]:
player_one_in_area = true
elif body [some check that guarantees player two]:
player_two_in_area = true
if player_one_in_area and player_two_in_area:
#change scenes here