How to check for two bodies colliding at once

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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?

:bust_in_silhouette: Reply From: timothybrentwood

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
:bust_in_silhouette: Reply From: vnmk8

use the area2D body_entered signal, when both players are inside the area set two vars to true when both are true change scene

var player_1_inside_area = false
var player_2_inside_area = false

func _physics_process(delta):
 if player_1_inside_area and player_2_inside_area:
   change_scene()

func _on_Area2D_body_entered(body):
  if body.is_in_group("player_1"):
     player_1_inside_area = true
  elif body.is_in_group("player_2"):
     player_2_inside_area = true

and i think you could also use setget to check for the vars value change instead of checking them on process every frame.