Topic was automatically imported from the old Question2Answer platform.
Asked By
YPestis
I’m trying to make the enemy keep shooting the projectiles when the player still in the area 2d collision shape, but they shoot only one time, and i need to enter again to they shoot the player, how do i make they keep shooting while the player stay in the area?
func _on_Range_body_entered(body):
if “player” in body.name and fireCooldown.is_stopped():
fireCooldown.start(cooldown)
fire()
body_entered only fires once per body that enters the area so you’ll need to set a boolean and use _physics_process() to cause it to shoot multiple times then use the body_exited signal to revert your boolean.
var player_in_range = false
func _physics_process():
if not player_in_range:
pass
elif fireCooldown.is_stopped():
fireCooldown.start(cooldown)
fire()
func _on_Range_body_entered(body):
if "player" in body.name:
player_in_range = true
func _on_Range_body_exited(body):
if "player" in body.name:
player_in_range = false