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.



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