How to disable Area2d collision

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.

I used

set_deferred("monitoring", false)

instead, which fixed it.

I think use _process or _physics_process, inside the _process use state true or false as states of colliding each other of two enemy and players or timer node indicates after that’s ended.

_on_hittable_obj_hit signal used for detecting node which collided with but after entering or exiting no matter how long is so that’s need repetitive or repeating detection inside the enemy’s body.

or build there’s such condition “if player after timer is ended but stay in enemy’s body it must happen more damage and more delaying damage” or player must raise such states for enemy’s body so enemy recognize the state by player after ended timer of player delaying damage and damage must happen. that decision must use repetition or repeating with _process or while or _physics_process.

it’s solved here, i found this idea

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.