Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dava |
I’m trying to make enemies perform certain behaviors when a player is present in the scene but when the player has queue_free()
, instead of the application crashing, the enemies would change behaviors. I tried using weakref
but the application just freezes when the enemy is present. Any suggestions? Here is my code:
onready var plr = get_node("/root/game/player")
var plrw = weakref(plr)
func _process(delta):
if !plrw.get_ref(): # Has the player gone
move_local_y(0)
if plrw.get_ref():
if get_pos().y < plr.get_pos().y:
move_local_y(SPEED)
if get_pos().y > plr.get_pos().y:
move_local_y(-SPEED)
pass
pass