How to make an enemy die when stomped?

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

I am very new to Godot and my first project is a simple mario-like platform with enemies that (should) die if you jump on them, but it’s not working

extends KinematicBody2D

onready var alive = get_tree().get_root().get_node("World/Player").alive
onready var spawn_point = get_tree().get_root().get_node("World/Player").spawn_point

func _ready():
	$area_enemy.connect("body_entered", self, "body_entered")
	$hitbox.connect("body_entered", self,"body_entered")
	
func on_area_enemy_body_entered(body):
	if body.name == "Player":
		alive = false
		print(alive)
		body.position = spawn_point
		alive = true 

And this is the code for when the player jumps on the enemy:

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

I am very much a noob and any kind of help is appreciated

:bust_in_silhouette: Reply From: Ertain

The code here, $hitbox.connect("body_entered", self,"body_entered"), calls the function, on_area_enemy_body_entered(), instead of calling on_hitbox_entered(). So the connection for the hitbox node may instead be:

$hitbox.connect("body_entered", self,"on_hitbox_entered")

It worked just fine but now when not hit on “hitbox” they still disappear after the player dies

Guiguis_Galdis | 2020-06-08 22:22