ft: predator mostly done
This commit is contained in:
1 parent
5f9a2fffb9
commit
8ee70854ea
16 files changed
+271
-30
No files matched your search
@@ -0,0 +1,26 @@
|
||||
extends State
|
||||
|
||||
var target: Node2D
|
||||
|
||||
func enter(previous_state_path: String, data := {}) -> void:
|
||||
if data.has("target"):
|
||||
target = data["target"]
|
||||
owner.sprite.play("Hunting")
|
||||
else:
|
||||
# default behaviour; do nothing
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
|
||||
func physics_update(_delta: float) -> void:
|
||||
if target == owner or target == null or owner.position.distance_to(target.position) > owner.sight_range:
|
||||
finished.emit(owner.fsm.States.IDLE, {})
|
||||
return
|
||||
|
||||
# alternatively, we could use a collision shape and inbuilt signals, but im not sure if that works better (mixing signals and custom fsm stuff i mean
|
||||
if owner.position.distance_to(target.position) > owner.attack_range:
|
||||
owner.move(move_towards(target.position))
|
||||
else:
|
||||
owner.attack(target)
|
||||
|
||||
func move_towards(pos: Vector2) -> Vector3:
|
||||
var diff = target.position - owner.position
|
||||
return Vector3(diff.x, diff.y ,0)
|
||||