ft: nucleotide prey FSM

This commit is contained in:
djaidjai committed 2026-01-26 23:54:15 +01:00
1 parent c11afd9ddd
commit adf1438bc8
18 files changed
+121 -45

No files matched your search

@@ -0,0 +1,22 @@
extends State
var threat: Node2D
var threshold: float = 100
func enter(previous_state_path: String, data := {}) -> void:
if data.has("threat"):
threat = data["threat"]
else:
# default behaviour; do nothing
threat = owner
func physics_update(_delta: float) -> void:
if owner.position.distance_to(threat.position) > threshold:
finished.emit(owner.fsm.States.IDLE, {})
return
owner.move(flee_from(threat.position))
func flee_from(pos: Vector2) -> Vector3:
var diff = threat.position - owner.position
diff = diff.normalized() * -1
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.