How do i continuously damage something when they are inside of area2d?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Regret666

So i been making a poison fog that when someone enter and stay they will get continuous damage the only problem is they only get damage once when they first enter,is there a way to fix this?(I’m only a beginner in godot)

:bust_in_silhouette: Reply From: mdubaisi

var in_fog = false
var damage = the damage you want
const PLAYER = preload(the player scene)

in the fog area entered function:
in_fog = true

in the fog area exited function:
in_fog = false

in the process function:
var player = PLAYER.instance()
player.health -= damage*delta

hope it works (:

:bust_in_silhouette: Reply From: Reloecc

I doubt you want to damage player every frame, so I recommend you add a Timer node to your “someone” scene. And enable timer if you enter poison cloud, and disable timer if you leave the poison cloud. Do the dmg in your timeout signal of the Timer.