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

@@ -18,6 +18,10 @@ func move(motion: Vector3, mod: float) -> void:
position = GameManager.get_boundaried_position(position)
func handle_damage(dmg: int, src: Node) -> void:
if owner:
owner.handle_damage(dmg, src)
func duplicate_init() -> void:
var sight = $Sight
remove_child(sight)

View File

@@ -55,7 +55,7 @@ animations = [{
script = ExtResource("2_0227s")
maxHealth = 20
[node name="Collision" type="CharacterBody2D" parent="." index="0" unique_id=331517910]
[node name="Collision" type="CharacterBody2D" parent="." index="0" unique_id=331517910 groups=["prey"]]
scale = Vector2(0.2, 0.2)
collision_layer = 2
collision_mask = 5

View File

@@ -1,6 +1,6 @@
extends State
var threat: Node2D
var threat: Node
var threshold: float = 100
func enter(previous_state_path: String, data := {}) -> void:
@@ -11,13 +11,12 @@ func enter(previous_state_path: String, data := {}) -> void:
finished.emit(owner.fsm.States.IDLE, {})
func physics_update(_delta: float) -> void:
if not is_instance_valid(threat) or GameManager.calc_distance(owner.position, threat.position) > threshold:
if not is_instance_valid(threat) or GameManager.calc_distance(owner.collision.position, threat.position) > threshold:
finished.emit(owner.fsm.States.IDLE, {})
return
owner.move(flee_from(threat.position))
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 = pos - owner.collision.position
diff = diff.normalized() * -1
return Vector3(diff.x, diff.y ,0)