ft (wip): tracking across boundaries

This commit is contained in:
2026-02-07 18:01:17 +01:00
parent 0f06846157
commit bc582efb90
12 changed files with 93 additions and 43 deletions

View File

@@ -64,9 +64,10 @@ visible = false
scale = Vector2(0.385, 0.385)
texture = ExtResource("2_68e2u")
[node name="WrappingManager" type="Node" parent="." unique_id=1406150436 node_paths=PackedStringArray("sprite")]
[node name="WrappingManager" type="Node" parent="." unique_id=1406150436 node_paths=PackedStringArray("sprite", "shape")]
script = ExtResource("3_8lhj0")
sprite = NodePath("../AnimatedSprite2D")
shape = NodePath("../CollisionShape2D")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1856148995]

View File

@@ -1,7 +1,6 @@
extends AbstractPredator2D
# FIXME: (general) tracking across wrapping boundary
# TODO: mirroring (thought, extracct that to general function/resource?
var can_attack: bool = true
var desired_rotation: float = self.rotation
@@ -19,7 +18,7 @@ func _ready() -> void:
health = maxHealth
sprite.play("Healthy")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# smoothly rotate

View File

@@ -100,23 +100,24 @@ script = ExtResource("1_xp037")
maxHealth = 50
metadata/_custom_type_script = "uid://dgfimmq53whll"
[node name="WrappingManager" type="Node" parent="." unique_id=826586678 node_paths=PackedStringArray("sprite")]
[node name="WrappingManager" type="Node" parent="." unique_id=826586678 node_paths=PackedStringArray("sprite", "shape")]
script = ExtResource("9_shhro")
sprite = NodePath("../AnimatedSprite2D")
shape = NodePath("../CollisionPolygon2D")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." unique_id=1596156928]
light_mask = 4
visibility_layer = 4
position = Vector2(0.111679085, 1.1167793)
rotation = -1.5707964
polygon = PackedVector2Array(-22.184862, -27.994831, 23.481365, -27.21198, 13.82622, 25.891317, -6.005971, 25.891317)
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=410999609]
rotation = 4.712389
sprite_frames = SubResource("SpriteFrames_shhro")
animation = &"Hunting"
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." unique_id=1596156928]
light_mask = 4
visibility_layer = 4
position = Vector2(0.11167908, 1.1167793)
rotation = -1.5707964
polygon = PackedVector2Array(-22.184862, -27.994831, 23.481365, -27.21198, 13.82622, 25.891317, -6.005971, 25.891317)
[node name="StateMachine" type="Node" parent="." unique_id=1857729810 node_paths=PackedStringArray("initial_state")]
script = ExtResource("3_xp037")
initial_state = NodePath("RandomMovement")

View File

@@ -11,12 +11,12 @@ func enter(previous_state_path: String, data := {}) -> void:
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:
if target == null or GameManager.calc_distance(owner.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 owner.position.distance_to(target.position) > owner.attack_range:
if GameManager.calc_distance(owner.position, target.position) > owner.attack_range:
owner.move(move_towards(target.position))
else:
owner.attack(target)

View File

@@ -58,9 +58,10 @@ script = ExtResource("2_0227s")
speed = 0.5
maxHealth = 20
[node name="WrappingManager" type="Node" parent="." index="0" unique_id=407460873 node_paths=PackedStringArray("sprite")]
[node name="WrappingManager" type="Node" parent="." index="0" unique_id=407460873 node_paths=PackedStringArray("sprite", "shape")]
script = ExtResource("3_lecx4")
sprite = NodePath("../AnimatedSprite2D")
shape = NodePath("../CollisionPolygon2D")
metadata/_custom_type_script = "uid://bvbc0n0pslq7p"
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="1" unique_id=788182944]

View File

@@ -11,7 +11,7 @@ func enter(previous_state_path: String, data := {}) -> void:
finished.emit(owner.fsm.States.IDLE, {})
func physics_update(_delta: float) -> void:
if owner.position.distance_to(threat.position) > threshold or threat == owner:
if GameManager.calc_distance(owner.position, threat.position) > threshold:
finished.emit(owner.fsm.States.IDLE, {})
return
owner.move(flee_from(threat.position))