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()