Killing player character

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dang_

I am really confused why the player character is not dying. In the enemy code I have already added:
func _on_Fire__body_entered(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??

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

ArthurER | 2020-10-05 12:55

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.

Bernard Cloutier | 2020-10-05 14:40

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()

razah | 2020-10-06 16:13

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.

Bernard Cloutier | 2020-10-06 19:07

:bust_in_silhouette: Reply From: cochise123

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)

this kills the enemy node

razah | 2020-10-06 16:04

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.

Millard | 2020-10-06 16:54

:bust_in_silhouette: Reply From: God Mod

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.