Restore camera controller

This commit is contained in:
2025-08-07 16:31:12 -05:00
parent a7dcf760a7
commit 0f3db7c4a4
4 changed files with 52 additions and 18 deletions

View File

@@ -1,6 +1,28 @@
class_name PlayerCamera extends Node
const CAMERA_PIXELS_PER_UNIT = 32.0
const CAMERA_PIXEL_SCALE = 1.0
@export var camera:Camera3D = null
@export var target:Node3D = null
func _process(delta: float) -> void:
pass
# I tried a few things but this is most consistent for both backbuffer and
# framebuffer viewports.
var viewportHeight = get_viewport().get_visible_rect().size.y;
var unitScale = CAMERA_PIXEL_SCALE * CAMERA_PIXELS_PER_UNIT;
var z:float = (
tan((deg_to_rad(180) - deg_to_rad(camera.fov)) / 2.0) *
(viewportHeight / 2.0)
) / unitScale;
var look = target.global_position;
var position = Vector3(0, 0, 2) + look;
camera.look_at_from_position(
Vector3(position.x, position.y + z, position.z),
look
);
pass