0 votes

Hi i am trying to program my enemy using animation tree as its a 2.5d enemy .

i have an attack radius area2d rectangle and i have connected signals for it to detect the player body but when the player enter the body the enemy only hits him once and doesnt keep attacking. is there any way to fix this?

in Engine by (25 points)

1 Answer

0 votes

Hi,
I did a similar thing with a missile launcher shooting at a space ship when it entered an area2d, like this:

In func _on_Radar_body_entered(body: Node) -> void: when the ship enters I set a bool to true to say it can be shot at.

In func _on_Radar_body_exited(body: Node) -> void: when the ship leaves I set the bool to false, so it can't be shot at.

Then in the _process function, if the bool is true, shoot the ship.

by (1,777 points)

Hi i tried but it did not work can you help me out? here is my code:

func attack_state(delta):
    animationstate.travel("attack")
    velocity = velocity.move_toward(Vector2.ZERO, friction * delta)

func _on_attackradius_body_entered(body):
    state = attack #this goes to the attack state above 

func _on_attackradius_body_exited(body):
    state = walk

happy to help.
Any chance you could upload your project (or a cut down version with just the scene/s that have the issue in them) ?

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 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 webmaster@godotengine.org with your username.