2024-02-07 22:04:19 +00:00
|
|
|
class_name RotationComponent
|
|
|
|
extends Node
|
|
|
|
|
|
|
|
@export var root: Node3D
|
|
|
|
@export var rotation_speed: float = 20.0
|
|
|
|
|
|
|
|
var direction: Vector3
|
|
|
|
var angle: float
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
assert(root, "Rotation root needs to be set")
|
2024-02-15 15:28:27 +00:00
|
|
|
owner.controller.direction_changed.connect(on_direction_changed)
|
2024-02-07 22:04:19 +00:00
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
root.rotation.y = lerp_angle(root.rotation.y, angle, rotation_speed * delta)
|
|
|
|
|
|
|
|
func on_direction_changed(new_direction: Vector3):
|
2024-02-15 15:28:27 +00:00
|
|
|
direction = new_direction
|
|
|
|
|
|
|
|
if direction != Vector3.ZERO:
|
|
|
|
angle = atan2(direction.x, direction.z)
|