I greet everyone and write again with the hope that someone will help. I wrote this code
func _on_attack_body_entered(body: Node3D) → void:
animation_player.play(“attack”)
if body.is_in_group(“igrok”) && body.has_method(“hurt”):
body.hurt(hit_point)
print(“hite”)
emit_signal(“hurt”)
So that the enemy would attack the hero during the course of the attack zone. However, how to make sure that he continues to attack while the character is inside the zone. I kind of tried to create a timer, but it still attacked only during the course of 1 time. , I don’t have any ideas thanks in advance.
I tested that on just print(“hite”) and yes, in general everything works. How can I send my signal now if it says that it is missing from the database for all options
make boolean variables and save the current target body, like
var can_attack:bool=false
var is_attacking:bool=false
var target_body=null
then in _physics_process function
func _physics_process(delta):
if can_attack:
if not is_attacking:
is_attacking=true
animation_player.play(“attack”)
if target_body:
if target_body.is_in_group(“igrok”) && target_body.has_method(“hurt”):
target_body.hurt(hit_point)
print(“hite”)
emit_signal(“hurt”)
await get_tree().create_timer(animation_player.get_current_animation_length()).timeout
is_attacking=false
then in func _on_attack_body_entered(body: Node3D) → void: function:
Yes, thank you very much, I realized that I should have added var target_body=null. But it still throws the error nonexistent function “hurt” in base Nill
I did everything in general and everything works, but I found an error that if another object of the RigidBody3D type is in the attack zone during the attack and the player leaves the attack zone, a crash occurs with the error nonexistent function is in group. there are some tips on what to do . I seem to have written if target_body.is_in_group(“igrok”) && target_body everywhere.has_method(“hurt”)
I apologize for the trouble I fixed, I deleted at the exit if target_body.is_in_group(“igrok") && target_body everywhere.has_method(“hurt”) . Thanks again