ft (wip): hammerhead predator
This commit is contained in:
22
evolve-die-repeat/molecular/prey/state_fleeing.gd
Normal file
22
evolve-die-repeat/molecular/prey/state_fleeing.gd
Normal file
@@ -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 or threat == owner:
|
||||
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