0 votes

I have put an area node under my game to respawn the player if they fall of but it won't detect the player. I have put a box collision shape for it and I have even put a method in the code. I think the code is where I am going wrong.

func on_body_entered():
    if body.is_in_group("player"):
        body.emit_signal("death")

death is the player's death signal so the level script can reassign coordinates to the player on its death.

in Engine by (34 points)

1 Answer

0 votes

Well there are a lot of possibilities here.

1) if the players group is called "Player" with a capital p and you have written "player" in the code above then it wont see the if block code.

2) If you have your player and other nodes on different levels then it may be that the collision node is not set up to detect any objects on the layer your player is on and thus this function is never activated

3) you may not have actually connected the signal of body entered to the function above

4) you may not have added a collision layer to your player.

Based on just the above it is impossible for me to say, there may even be another option but in principle at least your code above looks fine.

by (3,324 points)

thanks i'll see if any of these possibilities is the issue

Oh I have just thought of something try this

func on_body_entered(body):
    if body.is_in_group("player"):
        body.emit_signal("death")
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 Frequently asked questions and 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 [email protected] with your username.