Godot Version
4.3
Question
I want to create a player (Area2d) that collides with an enemy (Area2d)
I am using the area_entered signal which triggers this method trough code.
Since I don’t want my player to get hit multiple times from 1 hit, I want to implement immunity frames.
For this, I want to disable the collision for a while. I’m doing this like this:
func _on_hittable_obj_hit() -> void:
print("hit signal recived")
self.monitoring = false
print("startTimer")
await get_tree().create_timer(_playerImmunityTime).timeout
print("endTimer")
self.monitoring = true
When I walk into an enemy this is printed:
hit signal recived
startTimer
Then after the time is over
endTimer
The signal seems to not be send again despite the fact im still standing inside of the Enemy.
If I move in and out of the enemy without waiting for the timer to count down this happens:
hit signal recived
startTimer
hit signal recived
startTimer
hit signal recived
startTimer
hit signal recived
startTimer
hit signal recived
startTimer
endTimer
endTimer
endTimer
endTimer
endTimer
(I walked in 5 times here before waiting for the timers to count down)
This is not what I want at all.
I want for the collision to be disabled when the timer is running. For some reason, it seems to automatically enable itself when I leave the area.
Any ideas on how to fix this?
Thanks for your help.