diff --git a/src/player/orbital_camera/orbital_camera.gd b/src/player/orbital_camera/orbital_camera.gd new file mode 100644 index 0000000..d6d8200 --- /dev/null +++ b/src/player/orbital_camera/orbital_camera.gd @@ -0,0 +1,28 @@ +class_name OrbitalCamera extends Node3D + +const POSITION_ACCELERATION := 4.0 + +@export var target: Node3D + +@export var angular_speed := 0.01 + +@onready var camera: Camera3D = %Camera + +static var scene := preload("res://src/player/orbital_camera/orbital_camera.tscn") + + +func _physics_process(delta: float) -> void: + # Update position + global_position = global_position.lerp(target.global_position, delta * POSITION_ACCELERATION) + + # Update rotation + camera.look_at(target.global_position) + + # Update phase angle + rotation.y += angular_speed + + +static func create(_target: Node3D) -> OrbitalCamera: + var instance: OrbitalCamera = scene.instantiate() + instance.target = _target + return instance diff --git a/src/player/orbital_camera/orbital_camera.tscn b/src/player/orbital_camera/orbital_camera.tscn new file mode 100644 index 0000000..cf2dd0e --- /dev/null +++ b/src/player/orbital_camera/orbital_camera.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=2 format=3 uid="uid://de5onfk2tyr1d"] + +[ext_resource type="Script" path="res://src/player/orbital_camera/orbital_camera.gd" id="1_nvlic"] + +[node name="OrbitalCamera" type="Node3D"] +script = ExtResource("1_nvlic") + +[node name="Pitch" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.913545, 0.406737, 0, -0.406737, 0.913545, 0, 0, 0) + +[node name="Camera" type="Camera3D" parent="Pitch"] +unique_name_in_owner = true +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3) +current = true