A production-ready first-person camera controller for Unity with wall collision,
realistic headbob, aim zoom, and framerate-independent inputCompatible with Unity’s Built-in RP and tested with URP. Works with HDRP but may need minor tweaks for post-processing effects. Fully script-based, no SRP-specific dependencies, and supports all pipelines with minimal setup.`FirstPersonCameraScript` is a drop-in first-person camera controller built forUnity. Attach it to your camera, point it at your player, and you get smoothmouse look, FOV-based aim zoom, sinusoidal headbob, wall collision prevention,and a landing shake all configurable from the Inspector with no code required.## QUICK SETUP1. Add `FirstPersonCameraScript` to your Camera GameObject.2. Assign **Player Body** (your player root Transform) in the Inspector.3. Assign **Player Camera** (the Camera component) or leave blank toauto-detect.4. Assign **Player Controller** or leave blank to auto-detect.5. Set `Wall Collision Mask` to your environment layers (exclude the Playerlayer to avoid self-hit).6. Press Play.## TECHNICAL DETAILS| Property | Value || **Script language** | C# || **Namespace** | `FirstPersonCamera` || **Class name** | `FirstPersonCameraScript` || **Inherits from** | `MonoBehaviour` || **Update loops used** | `Update` (input / zoom / headbob), `LateUpdate` (position / wall collision) || **Physics API** | `Physics.SphereCastAll` — no Rigidbody required on the camera || **Input API** | Legacy `Input.GetAxis` / `Input.GetKey` || **Allocations at runtime** | `SphereCastAll` allocates a `RaycastHit[]` per frame when wall collision is enabled. All other logic is allocation-free. || **Number of scripts** | 2 (`FirstPersonCameraScript.cs`, `PlayerController.cs`) || **Number of lines (camera)** | ~400 || **Inspector headers** | 7 (Mouse Look, Constraints, Smoothing, References, Zoom/Aim, Wall Collision, Headbob + Landing) || **Public methods** | 5 (`SetMouseSensitivity`, `SetVerticalLimits`, `ResetRotation`, `SetInvertMouse`, `SetSmoothing`) || **Serialised fields** | 30 || **Minimum setup** | Attach script + assign Player Body — everything else auto-detects || **Render pipeline support** | Built-in RP, URP, HDRP || **Unity version minimum** | 2022.3 LTS || **Platform support** | Any platform that supports `Physics.SphereCastAll` and Legacy Input |AI tools were used to enhance the development workflow by assisting in writing clean, optimized, and well-commented code





