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,19 +1,15 @@
[gd_scene load_steps=11 format=3 uid="uid://2ch34sio36nv"]
[gd_scene load_steps=10 format=3 uid="uid://2ch34sio36nv"]
[ext_resource type="Script" uid="uid://ylmy3nvpirgr" path="res://entities/player/Player.gd" id="1_24gqh"]
[ext_resource type="Script" uid="uid://bwxdv3kxrs4oj" path="res://entities/player/PlayerMovement.gd" id="2_o7et6"]
[ext_resource type="Script" uid="uid://b3nty7pvbo58d" path="res://entities/player/PlayerInteraction.gd" id="3_24gqh"]
[ext_resource type="Script" uid="uid://bdv1fj1pwknrs" path="res://entities/player/PlayerInput.gd" id="4_yjynp"]
[ext_resource type="Script" uid="uid://bdjgvyiacbg28" path="res://entities/player/PlayerCamera.gd" id="5_g3lhm"]
[ext_resource type="Material" uid="uid://bx0778wr1ge00" path="res://materials/EntityMaterial.tres" id="6_4pwj0"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2m2ha"]
[sub_resource type="CapsuleMesh" id="CapsuleMesh_g13of"]
[sub_resource type="BoxMesh" id="BoxMesh_g13of"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_g13of"]
albedo_color = Color(0.0156863, 0.282353, 1, 1)
[sub_resource type="QuadMesh" id="QuadMesh_fmb3c"]
[sub_resource type="BoxShape3D" id="BoxShape3D_g13of"]
size = Vector3(0.705444, 0.680542, 1.17688)
@@ -37,20 +33,18 @@ script = ExtResource("4_yjynp")
interaction = NodePath("../PlayerInteraction")
movement = NodePath("../PlayerMovement")
[node name="PlayerCamera" type="Node" parent="Scripts" node_paths=PackedStringArray("camera")]
[node name="PlayerCamera" type="Node" parent="Scripts" node_paths=PackedStringArray("camera", "target")]
script = ExtResource("5_g3lhm")
camera = NodePath("../../PlayerCamera")
target = NodePath("../..")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_2m2ha")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("CapsuleMesh_g13of")
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
transform = Transform3D(0.598863, 0, 0, 0, 0.598863, 0, 0, 0, 0.598863, 0, 0.441532, 0.539694)
mesh = SubResource("BoxMesh_g13of")
surface_material_override/0 = SubResource("StandardMaterial3D_g13of")
[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)
mesh = SubResource("QuadMesh_fmb3c")
surface_material_override/0 = ExtResource("6_4pwj0")
[node name="PlayerInteractableArea" type="Area3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.185831, 0.817421)

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