Using orbital camera shot tracking

This commit is contained in:
Rob Kelly 2024-11-04 15:15:59 -07:00
parent a469af26f4
commit ecc425f10d
2 changed files with 42 additions and 0 deletions

View File

@ -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

View File

@ -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