2024-04-16 02:29:34 +00:00
|
|
|
extends Move
|
|
|
|
class_name MoveStraight
|
|
|
|
|
|
|
|
## A [Move] that moves in a fixed direction.
|
|
|
|
|
|
|
|
|
2024-04-17 02:52:11 +00:00
|
|
|
signal changed_direction(new: Vector2)
|
|
|
|
|
|
|
|
|
2024-04-17 03:29:45 +00:00
|
|
|
@export var speed: float = 100.0
|
|
|
|
|
2024-04-17 02:52:11 +00:00
|
|
|
@export var direction: Vector2:
|
|
|
|
get:
|
|
|
|
return direction
|
|
|
|
set(value):
|
|
|
|
direction = value
|
|
|
|
changed_direction.emit(direction)
|
2024-04-16 02:29:34 +00:00
|
|
|
|
|
|
|
|
2024-04-17 03:26:13 +00:00
|
|
|
func set_direction(value: Vector2) -> void:
|
|
|
|
direction = value
|
|
|
|
|
2024-04-30 02:38:27 +00:00
|
|
|
func steer_direction_towards(node: Node2D) -> void:
|
|
|
|
if node != null:
|
|
|
|
direction = global_position.direction_to(node.global_position)
|
|
|
|
|
2024-04-17 03:26:13 +00:00
|
|
|
func clear_direction() -> void:
|
|
|
|
direction = Vector2.ZERO
|
|
|
|
|
2024-04-16 02:29:34 +00:00
|
|
|
func randomize_direction() -> void:
|
|
|
|
direction = Vector2.from_angle(Random.rng.randf_range(0, 2*PI))
|
|
|
|
|
2024-04-30 02:38:27 +00:00
|
|
|
func randomize_direction_if_zero() -> void:
|
|
|
|
if direction == Vector2.ZERO:
|
|
|
|
randomize_direction()
|
|
|
|
|
2024-04-18 23:58:33 +00:00
|
|
|
func log_state() -> void:
|
|
|
|
Log.p(self, "Direction: %s | Speed: %s" % [direction, speed])
|
|
|
|
|
2024-04-30 02:38:27 +00:00
|
|
|
|
2024-04-17 03:29:45 +00:00
|
|
|
func _physics_process(delta: float) -> void:
|
2024-04-17 02:52:11 +00:00
|
|
|
if enabled:
|
2024-04-17 03:29:45 +00:00
|
|
|
move.emit(direction * delta * speed)
|