1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 16:14:22 +00:00
hella-farm/behaviours/move_straight.gd

36 lines
710 B
GDScript3
Raw Normal View History

extends Move
class_name MoveStraight
## A [Move] that moves in a fixed direction.
signal changed_direction(new: Vector2)
2024-04-17 03:29:45 +00:00
@export var speed: float = 100.0
@export var direction: Vector2:
get:
return direction
set(value):
direction = value
changed_direction.emit(direction)
2024-04-17 03:26:13 +00:00
func set_direction(value: Vector2) -> void:
direction = value
func clear_direction() -> void:
direction = Vector2.ZERO
func randomize_direction() -> void:
direction = Vector2.from_angle(Random.rng.randf_range(0, 2*PI))
2024-04-17 03:29:45 +00:00
func _physics_process(delta: float) -> void:
if enabled:
2024-04-17 03:29:45 +00:00
move.emit(direction * delta * speed)
2024-04-17 03:26:13 +00:00
func _on_changed_direction(new: Vector2) -> void:
Log.p(self, "Changed direction to: %s" % new)