0 votes

I am really confused why the player character is not dying. In the enemy code I have already added:
func onFire__bodyentered(body):
if body.get
name() == "Player":
body.queue_free()
and it does not die which is odd. I am not sure if this is because the character is unable to respawn or not. If so, is there a simple code for respawning??

in Engine by (39 points)

the function for the player to die should be in the player script.

Are you sure the line body.queue\_free() is executed? Try putting a print statement or a breakpoint, see if it's actually entering the if block.

In the enemy code I have already added:

Which child node did you add and what type.

If you print the scene tree with print_tree_pretty() in the root node and paste it here, the problem will be better understood.

extends Node

func _ready():
    print_tree_pretty()

Could you share what your player scene looks like? I have a suspicion that the "body" isn't at the root of your player scene. If that's the case, then freeing it would not free the other nodes in your player scene.

2 Answers

0 votes

In Your Code

func onFire__bodyentered(body):
if body.getname() == "Player":
body.queue_free()

Change It To This

func onFire__bodyentered(body):
if body.name == "Player":
queue_free()

(Note I Have Not Tested It But I Have A Feeling That This Will Work)

by (52 points)

this kills the enemy node

try what @cochise123 said, but type body.queue_free() instead. if you just type queue_free() it will destroy the object the script is attached to. that's why @cochise123's script destroyed your enemy.

0 votes

you can try this
func onFire__bodyentered(body):
if "player" on body.name:
body.queue_free()
but u wont be able to rewspawn cause its gonna delete the player and you can't bring it back. You can also change the player's location out of the screen for certain time and make it back again in a certain position. making it looks like respawning.

by (14 points)
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 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 webmaster@godotengine.org with your username.