Fix: fleeing from a removed object not handled

This commit is contained in:
Martin committed 2026-02-21 10:25:29 +01:00
1 parent 1ff04ff3b3
commit 7bd85cc050
1 file changed
+2 -1
@@ -11,12 +11,13 @@ func enter(previous_state_path: String, data := {}) -> void:
finished.emit(owner.fsm.States.IDLE, {}) finished.emit(owner.fsm.States.IDLE, {})
func physics_update(_delta: float) -> void: func physics_update(_delta: float) -> void:
if GameManager.calc_distance(owner.position, threat.position) > threshold: if not is_instance_valid(threat) or GameManager.calc_distance(owner.position, threat.position) > threshold:
finished.emit(owner.fsm.States.IDLE, {}) finished.emit(owner.fsm.States.IDLE, {})
return return
owner.move(flee_from(threat.position)) owner.move(flee_from(threat.position))
func flee_from(pos: Vector2) -> Vector3: func flee_from(pos: Vector2) -> Vector3:
# FIXME: What is the argument "pos" and why is it unused?
var diff = threat.position - owner.position var diff = threat.position - owner.position
diff = diff.normalized() * -1 diff = diff.normalized() * -1
return Vector3(diff.x, diff.y ,0) return Vector3(diff.x, diff.y ,0)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.