How To make the enemy detect the player and attack . Also how to make these attack collisions functionable

hey sorry man. i’ve updated the link access . you can see now in 1080P

func _on_player_detector_body_entered(body) -> void:
	if body is Player :

In the video it doesn’t have the little green arrow in the code gutter, could you show the connections to your player detector? I see it does have at least one, maybe it’s to another function?

Here it is , i fixed the gutter issue but still not working

Godot is case sensitive - that might be the issue.

Player != player

Can you expand your scene list as well?

It would throw an error if Player was not defined.

Sounds like it’s time to bust out print statements or look elsewhere. Make sure your samurai is not playing it’s walk animation every frame.

1 Like

I think you’re right. I’d also suggest trying

if == "Player":
1 Like

You can see in the window panel which is all the scene I have
Also Player is a class_name for my character body 2d

class_name Player

I can see the scripts but not the scenes…unless I’m missing something.

I’m a bit new to GDScript what does the → void do?

it’s an optional type declaration, in this case it says the function returns nothing.

I think I got it ,

my Samurai_walk_loop function is called by _process function which runs every frame

But on_body_entered runs only when the game starts like the _ready function, right?

In this case what I have to do?

It’s right under the 2D / 3D / script / assetlib where there are 5 tabs are opened like browser
These are all the scenes I have

Not play “Walk” every frame, use the auto play feature or start it on _ready. make a new connection from the animated sprite for animation_finished then when attack is done you can start walking again; maybe disable _process to prevent walking, or a new variable.

func _on_player_detector_body_entered(body) -> void:
	if body is Player :
		set_process(false) # stops walking

func _on_animated_sprited_animation_finished() -> void:
	if $AnimatedSprite2D.animation == "attack":
		set_process(true) # starts walking

The name of the tabs is the filename, it does not match class_name or the scene’s root node name, but I am sure the class_name is correct.

1 Like

Yeah the class_name is 100 % correct . And I think this will work . I’ll let you know when I’m done , Thanks mate . So much grateful to you

1 Like

Hey Man , so much grateful to you . It finally worked for me . Thanks for the time and help

1 Like

on_body_entered will signal/execute whenever something enters the collision shape.

That’s great - it’s a very good looking game. :smile:

Thanks Man . I am just in learning phase . Hopefully will make a full game very soon .

1 Like

I’m learning too!

I was previously making a 2d RPG but stopped when I was having too much trouble getting things to work.

I had a look at my RPG code yesterday and noticed a lot of code that I now know how to fix and improve.

1 Like