0 votes

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 onRangebodyentered(body):
if "player" in body.name and fireCooldown.is_stopped():
fireCooldown.start(cooldown)
fire()

in Engine by (17 points)

1 Answer

+2 votes
Best answer

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
by (3,882 points)
selected by

Ty so much dude, you helped me a lot. It works

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.