VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/camera-control-in-unity/

⇱ Camera Control In Unity - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Camera Control In Unity

Last Updated : 4 May, 2026

In Unity, the Camera is just another GameObject with a Camera component attached to it.

  • Every new 3D scene comes with a Main Camera by default
  • You can move, rotate, and scale it like any GameObject
  • The Camera component determines what the player sees on screen

Orthographic vs Perspective Camera

The Camera component has two projection modes that change how objects are rendered.

  • Perspective (3D): Objects appear smaller as they move away (realistic). Has Field of View property (typically 60-90 degrees). Used for FPS, RPG, and most 3D games.
  • Orthographic (2D): Objects stay the same size regardless of distance (flat). Has Size property instead of FOV. Used for 2D platformers, strategy games, and minimaps.

Simple Camera Follow

This is the most basic camera control – the camera strictly follows the target position.

  • offset creates distance between camera and target
  • Use LateUpdate() instead of Update() – camera moves after player, preventing jitter

Smooth Camera Follow

A smooth follow creates a polished, professional feel instead of instant snapping.

  • Vector3.Lerp() linearly interpolates between current and desired position
  • Higher smoothSpeed means faster following

Third-Person Orbit Camera

This camera rotates around the player when the mouse moves – common in action RPGs.

  • Yaw: Horizontal rotation (left/right)
  • Pitch: Vertical rotation (up/down)
  • Mathf.Clamp() prevents looking too far up or down

First-Person Mouse Look

For FPS games, the camera acts as the player's eyes and is attached to the player body.

  • Camera must be a child of the player body GameObject
  • Body rotates left/right (yaw), camera rotates up/down (pitch)
  • Prevents the entire body from tilting when looking up

Camera Shake

Camera shake adds impact feedback for explosions, hits, or landings.

  • Random.insideUnitSphere creates random offset in all directions
  • Call Shake(0.3f) when player takes damage or an explosion occurs

Camera Zoom

Zoom changes the camera's field of view (3D) or orthographic size (2D) for effects like aiming or scoping.

For 3D (Perspective camera)

For 2D (Orthographic camera)

Common Mistakes

  • Using Update() instead of LateUpdate() – causes camera lag behind player
  • Not clamping pitch values – camera flips over when looking straight up/down
  • Moving camera with physics in FixedUpdate() – use LateUpdate() instead
  • Forgetting to test different aspect ratios – camera may show unintended areas
Comment
Article Tags:
Article Tags:

Explore