system
November 17, 2017, 4:32am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
Newby
Old Version
Published before Godot 3 was released.
when my enemy’s health is 0 i want the area2d to queue_free() before the sprite queue_free() so the player wont get hurt to a dead enemy
Detail a bit more how is the sequence of events you want to get (I think your issue is with the collision/overlap management).
system
November 17, 2017, 5:14am
4
Reply From:
SidCoalman
Here is one way to do it:
extends WhateverNode
var disabled = false
func _on_hit_player_area():
if !disabled():
player.take_harm()
func kill_enemy():
disabled = true
queue_free()
Sorry for the bad code readability, the code block seems to not enable indentation.
Anyway, basically:
Before you harm your player, check to see if this enemy is disabled.
When your enemy dies, put it to disabled (a custom variable). That way, it will not do stuff you don’t want it to while you wait for it to free.
edit to look better code format
volzhs | 2017-11-17 08:08
i just want to know how to queue_free() the area2d pls
system
November 17, 2017, 11:45pm
5
Reply From:
SidCoalman
Take my previous answer: using disabled = true.
Deleting the area2d through queue_free() will still cause the same theoritical problem of the enemy possibly harming your character while waiting to die.
None the less, if you must, here is how:
get_node("your_area2D").queue_free()
Thanks the disable thing work but now to collision doesnt queue free now so i need find out how to fix that other than that it works.
8