From 8278a55069dcffc617c1f4a713835fe1e44e8898 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 17 Apr 2024 05:29:45 +0200 Subject: [PATCH] It works --- behaviours/move_straight.gd | 6 ++++-- behaviours/move_towards.gd | 6 ++++-- entities/sheep.tscn | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/behaviours/move_straight.gd b/behaviours/move_straight.gd index 86f5bc1..a483c31 100644 --- a/behaviours/move_straight.gd +++ b/behaviours/move_straight.gd @@ -7,6 +7,8 @@ class_name MoveStraight signal changed_direction(new: Vector2) +@export var speed: float = 100.0 + @export var direction: Vector2: get: return direction @@ -25,9 +27,9 @@ func randomize_direction() -> void: direction = Vector2.from_angle(Random.rng.randf_range(0, 2*PI)) -func _physics_process(_delta: float) -> void: +func _physics_process(delta: float) -> void: if enabled: - move.emit(direction) + move.emit(direction * delta * speed) func _on_changed_direction(new: Vector2) -> void: Log.p(self, "Changed direction to: %s" % new) diff --git a/behaviours/move_towards.gd b/behaviours/move_towards.gd index 058b20e..5e07d57 100644 --- a/behaviours/move_towards.gd +++ b/behaviours/move_towards.gd @@ -8,6 +8,8 @@ class_name MoveTowards signal changed_target(new: Node2D) +@export var speed: float = 100.0 + @export var target: Node2D = null: get: return target @@ -23,12 +25,12 @@ func clear_target() -> void: target = null -func _physics_process(_delta: float) -> void: +func _physics_process(delta: float) -> void: if enabled: if target: var gap = target.global_position - global_position var norm = gap.normalized() - move.emit(norm) + move.emit(norm * delta * speed) else: move.emit(Vector2.ZERO) diff --git a/entities/sheep.tscn b/entities/sheep.tscn index d71578e..fef9b2e 100644 --- a/entities/sheep.tscn +++ b/entities/sheep.tscn @@ -117,6 +117,7 @@ libraries = { possibilities = [NodePath("../MovementIdle/IdlePriority"), NodePath("../MovementWander/WanderPriority"), NodePath("../MovementRunFromMouse/RunFromMousePriority"), NodePath("../MovementRunFromHunter/RunFromHunterPriority")] [node name="MovementIdle" parent="." instance=ExtResource("10_05kcd")] +speed = 0.0 enabled = false [node name="IdlePriority" parent="MovementIdle" instance=ExtResource("11_0jlmk")] @@ -126,6 +127,7 @@ priority = 10 one_shot = true [node name="MovementWander" parent="." instance=ExtResource("10_05kcd")] +speed = 66.0 enabled = false [node name="WanderPriority" parent="MovementWander" instance=ExtResource("11_0jlmk")] @@ -134,6 +136,7 @@ enabled = false one_shot = true [node name="MovementRunFromMouse" parent="." instance=ExtResource("12_x2g3x")] +speed = -100.0 enabled = false [node name="RunFromMousePriority" parent="MovementRunFromMouse" instance=ExtResource("11_0jlmk")] @@ -145,6 +148,7 @@ shape = SubResource("CircleShape2D_etpf6") debug_color = Color(1, 0, 0, 0.0470588) [node name="MovementRunFromHunter" parent="." instance=ExtResource("12_x2g3x")] +speed = -100.0 enabled = false [node name="RunFromHunterPriority" parent="MovementRunFromHunter" instance=ExtResource("11_0jlmk")]