Journal 66 — In “The Great Fleece”, Add Camera Triggers

Objective: To add functionality to change the camera view using triggers

In the example below from “The Great Fleece”, there are series of camera angles that can change as Darren progresses through the Auction House. There are triggers along the floor that can be used to update the camera view. Let’s set them up.

First, we need a new C# script, such as CameraTrigger. We can assign this to the Camera triggers, as shown below.

The basic pseudocode is: if the player enters the trigger, to change the camera progression angle. For now, we can start with a basic test, to write a Debug.Log message when the Player, Darren, activates a trigger.

When I first tried this approach in Playmode, Darren could not pass through the trigger. I needed to look back in the Unity docs for the conditions.

So I added a Rigidbody to the Camera trigger game object, and made sure to check the trigger for each Camera trigger game object.

Let’s test this.

Next we need to update the script to change the main camera view as each camera trigger is activated.

We can add a Transform variable to hold the position and rotation of each new camera view via a single script for all the camera triggers.

One last update to the camera movement is to have the Main Camera center on the Player and follow their movement. We can make a short C# script and attach it to the Main Camera. We can use the LookAt function. After the script compiles, make sure to drag the Player game object onto the Main Camera (I missed this and wondered why it wasn’t working……..).

Finally, here is the updated camera movement and triggers in Playmode.

Thank you for your time!

--

--

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