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

@@ -39,7 +39,7 @@ func attack(target: Node) -> void:
var hit_hittable = false
if target.is_in_group("prey") or target.is_in_group("player"):
if target.has_method("handle_damage"):
target.handle_damage(damage, self)
target.handle_damage(damage, self.collision)
hit_hittable = true
elif target.is_in_group("resources"):
# TODO: resource handling logic

View File

@@ -92,12 +92,12 @@ animations = [{
"speed": 5.0
}]
[node name="HammerheadPredator" type="Node" unique_id=1312337720 groups=["predator"]]
[node name="HammerheadPredator" type="Node" unique_id=1312337720]
script = ExtResource("1_xp037")
maxHealth = 50
metadata/_custom_type_script = "uid://dgfimmq53whll"
[node name="Collision" type="CharacterBody2D" parent="." unique_id=76553184]
[node name="Collision" type="CharacterBody2D" parent="." unique_id=76553184 groups=["predator"]]
scale = Vector2(0.8, 0.8)
collision_layer = 4
collision_mask = 3

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)