How to continuously check collisions in an Area2D?

Godot Version

4.2.1

Question

Please see the linked video.

My requirement is to constantly check for collisions on the Player_Hitbox (Area2D).

The damage is applied as expected when the player collides with an enemy for the first time. When the player leaves the enemy hitbox and collides again, the damage is applied as expected.

But if the player remains on the enemy without exiting the enemy_hitbox, the player_hitbox area does not register the collision.
What I’m trying to achieve here is that if the player remains within the enemy_hitbox, the damage should be applied constantly, once the invincibility status runs out.

I’ve read that the best way to achieve this is to use get_overlapping_areas or overlaps_area methods. However, I have no idea how to implement these into my code.

area_entered signal code, damage apply, and invincibility codes are below.

Thank you in advance.

Invincibility:

func go_invincible():
	invincible = true
	animation_player_invincible.play("invincible")
	invincible_timer.start()       #3 seconds

func _on_invincible_timer_super_timeout():
	invincible = false

area_entered, Hurt, and Apply damage:

func apply_hit_normal_damage():
	if invincible == true:
		return

	if is_shielded == false:
		is_hurt = true
		go_invincible()
		current_health -= 1
	else:
		if current_shield_amount <= 0:
			is_hurt = true
			go_invincible()
			current_health -= 1
			
		else:
			current_shield_amount -= 1
	
	Signalmanager.on_player_hit.emit(current_shield_amount, current_health)

func apply_hit_mega_damage():
	if invincible == true:
		return

	if is_shielded == false:
		is_hurt = true
		go_invincible()
		current_health -= 2
	else:
		if current_shield_amount <= 0:	
			is_hurt = true
			go_invincible()
			current_health -= 2
			
		else:
			current_shield_amount -= 2
		
	Signalmanager.on_player_hit.emit(current_shield_amount, current_health)



func _on_player_hitbox_area_entered(area):
	if area.is_in_group("enemy_bullet") or area.is_in_group("enemy_hitbox"):
		apply_hit_normal_damage()
	if area.is_in_group("enemy_bomb_explosion"):
		apply_hit_mega_damage()

The area_entered signal is triggered only when the area enter the first time inside the area so after you enter the area, you need to leave and enter again to trigger this signal, for what you want you can do this:

  1. Connect the area_exited signal on your character code
  2. Create a Timer node and connect the timeout signal in your character script
  3. Set the wait_time for the amount of time between the hits (don’t forget to set as one-shot)
  4. In the area entered function, separete enemy_bullet and enemy_hitbox in different checks
  5. In the enemy_hitbox check, after apply the normal damage, start the timer
  6. In the timeout function, call the normal damage function and restart the timer
  7. In your area exited function, check if the area exited is an enemy_hitbox, and if is, stop the timer

A hack I’ve used in the past is to disable and enable the Area2d collision shape or set turn off and on monitoring when the player is hit. I find this easier to manage.

A much more safe option is to use get_overlapping_bodies() function of Area2d and damage the player if it’s detected. I’ve found that this method is not reliable though, unless you wait for multiple frames.