Camera Look at Player

Creating a script to allow camera to always look at player

After we have set up the camera triggers and updating camera angles, we might have noticed that there are some sections of the map which the player goes off screen, we can fix this issue with an Look at script which allows the Main camera to always be focused on the player.

Look At Script

Create a new script file within the Script folder and name it “LookAt”. Within the script we are basically going give an public variable a handle and use one command which is “Transform.LookAt”. The handle is going to be our target transform component which we can name “target” and within void Update since we want this to occur every second. We are going to place the code “transform.LookAt(target);”

Then drag the script into the Main Camera object and drop the Player into the Target slot. After saving and playing you will see that the Main camera now Pans across the room always looking at the player.

In the next article, we will focus on Player Animation and also update the Player Renderer to have Darren’s 3D model.

--

--

--

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

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

Recommended from Medium

Node.js — Serve Private Content using AWS CloudFront

Using Mocha for Test-Driven Development in building API with Node / Express

Introduction to React Query — Performance Optimisation

ReactJS vs React Native — Differences

Full-Stack Developer Roadmap 2022 — Web Development 📜

Full Stack development Roadmap 2021 and 2022 — Programming

GatsbyJS — Building Static “Stallion” Websites That Outrun the Rest

The Array Data Structure in JavaScript.

Integrating FCM in React Native and processing FCM messages even in background.

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Level Design in Unity Part 2: The Walls

Creating the Main Menu

How to Make the Camera Shake Using Impulse Listener Extensions in Cinemachines Virtual Cameras

Working with Screen Space Reflections in Unity’s HDRP