Creating A Simple Smooth Camera Controller For A 2D Unity Game

Today I am creating a camera controller to follow the player, including offsets, dead-zones, and movement smoothing.

Today’s Objective: Create a good quality yet simple camera controller to keep the player in frame regardless of speed, while moving smoothly.

The Code:

I create a new script called “CameraController”, and create variables to manage the deadzone, smoothing, and move speed:

The functionality is simply lerping to the target position each frame, while clamping the position within the deadzone:

Because the position is set in the FixedUpdate, it smoothly follows the physics of the character’s movements for the most part with little visible flickering.

--

--

--

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to know if software outsourcing is a good fit for you, without wasting valuable time

Setup Virt-Manager, Qemu, libvert and KVM on Ubuntu 20.04

Welcome to The Commons Ivan!

Latex Product ImprovePerformance https://t.co/ctad4n0Wid

Udacity VRND Capstone “Murder Dream”

Introduction To Pytorch And Operations

Let’s speak about testnet tasks!

Monitor your dataLayer’s quality in real-time using Google Tag Manager and Firebase

real-time notification for dataLayer errors using firebase and google tag manager

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

More from Medium

Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 5)

Shooting Enemies in Unity.

Quick tip — Upgrading your Unity project to High Definition Render Pipeline (HDRP)

Mastering Unity Scripting | Summary — Chapter 1: Unity C# Refresher