#Death animation not playing when player collides with enemu

1 messages · Page 1 of 1 (latest)

misty tartan
#

i genuinely have no clue what to do here.
im trying to follow a tutorial and uh....

whenever i begin to debug it, everytime the player comes into contact with the enemy, it doesnt play the death animation.

help wanted!

misty tartan
#

func die() -> void:
animated_sprite_2d.animation = "dying
alive = false

arctic gull
#

[]cb

hexed hingeBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ``` (3 backticks. Click here to see where the key is)

To use syntax highlighting, add the file extension of the language you wish to highlight (cs for C#, cpp for C++)

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

arctic gull
#

but how are you calling it?

misty tartan
#

calling it?

arctic gull
#

the die function

#

where are you calling it from

misty tartan
#

player scene?

arctic gull
#

elaborate

#

are you using a signal?

misty tartan
#

"player_died"

arctic gull
#

is that a signal you've defined?

misty tartan
arctic gull
#

that's not connected to anything

misty tartan
#

the body.die()?

arctic gull
#

no i mean the _on_player_died function doesn't have a signal connected to it

#

if it did, it'd have a little green arrow icon to the left of the line number

misty tartan
#

green arrow icon?

arctic gull
#

you don't have that, so it's not connected to a signal

misty tartan
#

how do i connect it?

arctic gull
#

select your node (probably an area2d?), go into the 'Node' tab and connect the signal you want to the _on_player_died function

#

what's the script with _on_player_died on?

misty tartan
arctic gull
#

alright, then go to the snail scene and connect the signal to the function (in the 'node' tab)

misty tartan
#

its connected, i think?

arctic gull
#

does the method have an arrow icon next to it

#

like this

misty tartan
#

on the signals tab it does but i dont see it on the script itself

arctic gull
#

did you connect it to the right method?

misty tartan
#

oh now it does-

arctic gull
#

should work now then

misty tartan
#

wait-

#

OH

#

the target???

arctic gull
#

what target?

misty tartan
arctic gull
#

that's saying that this method (_on_body_entered, which isn't the _on_player_died method) has a body_entered signal connected to it from the source Snail area2d to a target Snail area2d (they're the same node)

#

you connected it to a different method it looks like

misty tartan
#

where is it meant to be??

arctic gull
#

what function do you want to get called when a body enters the area?

misty tartan
#

on_player_died

arctic gull
#

then connect it to that function

#

there's a little pencil icon you can press to select a method when connecting it iirc

misty tartan
#

where do i find that?

arctic gull
#

when you're connecting the signal

misty tartan
#

this?

#

what do i do??

arctic gull
#

it lets you select a method from the scirpt

misty tartan
#

ok....

arctic gull
#

well

#

what do you think you need to do here?

misty tartan
#

idk???

arctic gull
#

what method do you want to connect the signal to

#

select that method

misty tartan
#

on_player_died?

arctic gull
#

yeah

misty tartan
#

this then popped up

arctic gull
#

what are you doing in the _on_body_entered bit?

arctic gull
misty tartan
#

huh?

arctic gull
#

you want the body_entered signal to call _on_player_died

misty tartan
#

oh

arctic gull
#

which then calls die on the body

misty tartan
#

this one?

arctic gull
#

yeah

#

now select the _on_player_died method

misty tartan
#

ah huh?

arctic gull
#

in the pick menu

#

though it might not show it if it doesn't have a body param? not sure

#

but you'll have to add it anyways

misty tartan
arctic gull
#

yeah

#

choose the method you need

misty tartan
#

which is the last one?

arctic gull
#

well yeah

misty tartan
#

this popped up

arctic gull
#

yeah now just call the die method on body if it's the player

#

and you don't even need the _on_body_entered function

misty tartan
#

what do i put under "func _on_player_died(body: Node2D) -> void:"?

arctic gull
#

well whatever was there at the start

misty tartan
#

do i just get rid of the "func _on_body_entered(body: Node2D) -> void:" above that??

arctic gull
#

yeah

misty tartan
#

now what??

arctic gull
#

now run it

misty tartan
#

i did

arctic gull
#

so what happened?

misty tartan
#

nothings happening

arctic gull
#

did you put anything on _on_player_died

misty tartan
#

how do i check that?

arctic gull
#

by looking at it???

misty tartan
arctic gull
#

what's in the _on_player_died function

misty tartan
arctic gull
#

that's not what i asked

misty tartan
#

ah-

#

where do i check??

arctic gull
#

look at the function...

misty tartan
#

"if body.name == "Player":"
"emit_signal("player_died", body)"

arctic gull
#

uh

#

what do you think this is doing?

misty tartan
#

no clue

arctic gull
#

then why did you write it

#

think about what you actually want the function to do