How do i actualy use timers in a _physics_process()
variable context inHurtZone Variable that i have changing based on if in an area playerHealth player health hurtDamage the amount of damage inflicted onto the player (in this case it’s set to 10)
You know _physics_process is called 60 times per second right? Unless you have a big hp, the player will die fast because is losing 600 hp per second. If you want to do a DoT damage you need to use a Timer node instead and in your _physics_process you’ll just make sure to start/stop the timer.
Create a Timer node
Connect the timeout signal to your code
Set the timer node autoplay to false and one-shot to false too
Set the wait time to 0.5 (or any value you want to wait between the damage ticks)
# Code
# Create a var to know if you're already_applying the dot
var is_applying_dot := false
func _physics_process(delta) -> void:
# Check if is inside the damage zone and if the dot is already applying
if inHurtZone == true and is_applying_dot == false:
# Set the variable to true and start the timer
is_applying_dot = true
$Timer.start(0.5)
# If player is outside the damage area but was taking damage before makes the damage stop
elif inHurtZone == false and is_applying_dot == true:
is_applying_dot = false
$Timer.stop()
func _on_Timer_timerout() -> void:
playerHealth -= hurtDamage