Files
Dawn-Godot/scripts/Entity/RosaCamera.gd
2025-05-09 22:33:51 -05:00

30 lines
661 B
GDScript

extends Camera3D
@export var pixelScale:float = 1.0;
@export var follow:Node3D;
const WORLD_UNITS:float = 32.0;
func _ready() -> void:
pass
func _process(delta: float) -> void:
# 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 = pixelScale * WORLD_UNITS;
var z:float = (
tan((deg_to_rad(180) - deg_to_rad(fov)) / 2.0) *
(viewportHeight / 2.0)
) / unitScale;
var look = follow.position;
var position = Vector3(0, 0, 2) + look;
look_at_from_position(
Vector3(position.x, position.y + z, position.z),
look
);