## The local player's third-person camera. Turns mouse motion into a look direction using ## InputSettings, and places itself each frame with CameraRig, so it never clips through ## terrain or structures. The input layer reads `yaw` and `pitch` when it builds the ## player's commands. class_name PlayerCamera extends Camera3D var settings: InputSettings = InputSettings.new() var rig: CameraRig = CameraRig.new() var ground: SimGround = SimGround.flat() ## Radians, in the simulation's convention (see docs/ARCHITECTURE.md). var yaw: float = 0.0 var pitch: float = 0.0 var aiming: bool = false ## Where the followed player's feet are, and whether they're crouching. Set by whoever ## owns the player's presentation, from interpolated snapshots. var target_feet: Vector3 = Vector3.ZERO var target_crouching: bool = false func _ready() -> void: near = CameraRig.NEAR fov = CameraRig.FOV func _unhandled_input(event: InputEvent) -> void: var motion: InputEventMouseMotion = event as InputEventMouseMotion if motion != null and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: var look: Vector2 = settings.apply_mouse(motion.relative, yaw, pitch, aiming) yaw = look.x pitch = look.y func _process(delta: float) -> void: rig.update_aim(aiming, delta) snap() ## Places the camera for the current target and look direction immediately. func snap() -> void: global_transform = rig.solve(target_feet, yaw, pitch, target_crouching, ground) fov = rig.fov()