fx: prey-predator interactions

This commit is contained in:
2026-03-01 14:55:25 +01:00
parent f83b290f5c
commit 2b46fd18f7
8 changed files with 15 additions and 16 deletions

View File

@@ -11,16 +11,16 @@ func enter(previous_state_path: String, data := {}) -> void:
finished.emit(owner.fsm.States.IDLE, {})
func physics_update(_delta: float) -> void:
if target == null or GameManager.calc_distance(owner.position, target.position) > owner.sight_range:
if target == null or GameManager.calc_distance(owner.collision.position, 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 GameManager.calc_distance(owner.position, target.position) > owner.attack_range:
if GameManager.calc_distance(owner.collision.position, 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
var diff = target.position - owner.collision.position
return Vector3(diff.x, diff.y ,0)