1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 23:54:23 +00:00
This commit is contained in:
Steffo 2024-04-17 05:29:45 +02:00
parent 3341c86e39
commit 8278a55069
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
3 changed files with 12 additions and 4 deletions

View file

@ -7,6 +7,8 @@ class_name MoveStraight
signal changed_direction(new: Vector2) signal changed_direction(new: Vector2)
@export var speed: float = 100.0
@export var direction: Vector2: @export var direction: Vector2:
get: get:
return direction return direction
@ -25,9 +27,9 @@ func randomize_direction() -> void:
direction = Vector2.from_angle(Random.rng.randf_range(0, 2*PI)) 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: if enabled:
move.emit(direction) move.emit(direction * delta * speed)
func _on_changed_direction(new: Vector2) -> void: func _on_changed_direction(new: Vector2) -> void:
Log.p(self, "Changed direction to: %s" % new) Log.p(self, "Changed direction to: %s" % new)

View file

@ -8,6 +8,8 @@ class_name MoveTowards
signal changed_target(new: Node2D) signal changed_target(new: Node2D)
@export var speed: float = 100.0
@export var target: Node2D = null: @export var target: Node2D = null:
get: get:
return target return target
@ -23,12 +25,12 @@ func clear_target() -> void:
target = null target = null
func _physics_process(_delta: float) -> void: func _physics_process(delta: float) -> void:
if enabled: if enabled:
if target: if target:
var gap = target.global_position - global_position var gap = target.global_position - global_position
var norm = gap.normalized() var norm = gap.normalized()
move.emit(norm) move.emit(norm * delta * speed)
else: else:
move.emit(Vector2.ZERO) move.emit(Vector2.ZERO)

View file

@ -117,6 +117,7 @@ libraries = {
possibilities = [NodePath("../MovementIdle/IdlePriority"), NodePath("../MovementWander/WanderPriority"), NodePath("../MovementRunFromMouse/RunFromMousePriority"), NodePath("../MovementRunFromHunter/RunFromHunterPriority")] possibilities = [NodePath("../MovementIdle/IdlePriority"), NodePath("../MovementWander/WanderPriority"), NodePath("../MovementRunFromMouse/RunFromMousePriority"), NodePath("../MovementRunFromHunter/RunFromHunterPriority")]
[node name="MovementIdle" parent="." instance=ExtResource("10_05kcd")] [node name="MovementIdle" parent="." instance=ExtResource("10_05kcd")]
speed = 0.0
enabled = false enabled = false
[node name="IdlePriority" parent="MovementIdle" instance=ExtResource("11_0jlmk")] [node name="IdlePriority" parent="MovementIdle" instance=ExtResource("11_0jlmk")]
@ -126,6 +127,7 @@ priority = 10
one_shot = true one_shot = true
[node name="MovementWander" parent="." instance=ExtResource("10_05kcd")] [node name="MovementWander" parent="." instance=ExtResource("10_05kcd")]
speed = 66.0
enabled = false enabled = false
[node name="WanderPriority" parent="MovementWander" instance=ExtResource("11_0jlmk")] [node name="WanderPriority" parent="MovementWander" instance=ExtResource("11_0jlmk")]
@ -134,6 +136,7 @@ enabled = false
one_shot = true one_shot = true
[node name="MovementRunFromMouse" parent="." instance=ExtResource("12_x2g3x")] [node name="MovementRunFromMouse" parent="." instance=ExtResource("12_x2g3x")]
speed = -100.0
enabled = false enabled = false
[node name="RunFromMousePriority" parent="MovementRunFromMouse" instance=ExtResource("11_0jlmk")] [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) debug_color = Color(1, 0, 0, 0.0470588)
[node name="MovementRunFromHunter" parent="." instance=ExtResource("12_x2g3x")] [node name="MovementRunFromHunter" parent="." instance=ExtResource("12_x2g3x")]
speed = -100.0
enabled = false enabled = false
[node name="RunFromHunterPriority" parent="MovementRunFromHunter" instance=ExtResource("11_0jlmk")] [node name="RunFromHunterPriority" parent="MovementRunFromHunter" instance=ExtResource("11_0jlmk")]