Triggering a death animation using on_body_entered and signals

Okay, you can do it in inspector, but I prefer personally to do it in code so I can see it faster if there is an area.

So, in your player code I would write this.

func _ready() -> void:
     add_to_group("player")

This is the reason that your if body.is_in_group("player"): wasn’t working.

Ah ok. Yes I can’t any group thing in the inspector I’ll add the code instead. Easier to see later.
You are helping no end, really appreciate it!

No worries man, so many people have helped me out along the way. Still have so much to learn, so if I can help out a little I will.

Also, for future reference if you want to handle groups in inspector it is in the same window as signals, at the top there are two choices signals and groups, just click the groups.

Ah yeah I see it now!
I got the group “player” working now in the killzone script.

The body._on_killzone_player_died() throws an error, I’m not sure what this is for yet so I commented it out and so far so good. just gotta figure out calling this death animation, not sure how to access it properly from the killzone script if we’re not using a signal over to the player script. I think need a alive check some how so it cancels out the movements because they are obviously triggering too when I hitting the enemy killzone. Feel like I’m getting closer. :sweat_smile:

Always nice with progress.

What is the error that it is giving you?

So, the alive check you can do in players code, at the top of the phyisics func.

func _physics_process(delta):
     if not alive:
          return

#after comes the rest of your code

So, also don’t worry about initiating death animation from killzone, the animation is in your proto node right? That node is a child of player. So, in your player script _on_killzone_player_died(): call your animation from proto.

Ah ok, starting to see the light a little more haha.
Do I need to declare a variable for alive first then add the if not alive: ?
Gonna try all this out now.

Yes so create a var alive : bool = true, you will then turn this false in your _on_killzone_player_died(): before calling the animation

func _on_kill_zone_player_died():
		alive = false
		$proto.play("explode")

I got this in player script now, it’s giving an error : stanalone lambdas cannot be accessed, consider assigning a variable.

I have bode. _on_killzone_player_died() running in the killzone script now too.

Oh I put it outside the physics_process function if that’s correct.

Ahh, yeah no that is why you are getting the error, you need to put the if not alive: return in the physics_process.

yes I have if not alive at the start of the physics_process func
but the other func_on_killzone_player is outside the physics_process function

I corrected the func , shouldn’t be _ between kill and zone.

Okay, cool.

So, is it doing what you wanted to? Or where are you at on that department, have you managed to get the death animation triggering?

no I’m getting this weird error

Man I’m so sorry this turned out to be pretty complicated and you are so kind to spend this much time. I’m gonna keep digging away and try to fix this error.
:pray:

That is an easy error to fix.

You have an indent before the func()

You are trying to imbed the func into your physics_process, which makes it think it is a lambdas, however, there is no way to access this lambdas so it is throwing the error.

Just delete the indent before your func() and it will be fixed.

Yeah! I just googled it and found out! It works. I can’t thank you enough, seriously. That was a masterclass in gdscript. I’m humbled by your generosity!

1 Like

Just a quick demo of the results

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.