The Great Fleece: Camera Angles
--
In this article, we’ll check out how to switch between different camera angles using a modular approach. We’ll only be using one script for this. Lets go!
Check out the “Level_Colliders” game object. You’ll see some colliders stretching all the way across the floor. These are going to be what changes the camera angle. When Darren Collides with one of these, the camera will switch angles.
How does it switch angles you ask? Check out the “Camera_Progression_Angles” game object. If you collapse that you’ll see several different cameras.
In the previous article we set our Main Camera’s initial position to the Camera_one position. Now we need to change the Main Camera’s position depending on what Collider we just hit through code! FUN!
Create a new script called CameraTrigger. What are we going to attach this to? Glad you asked! Check out the “Camera_progression_Triggers” game object. Select all the children of that game object and add the script to them.
Now for the code part. Its actually pretty easy. Create a public variable for the transform. I called mine “myCamera”. You should call yours something you’ll remember what it means.
We set up an OnTriggerEnter function JUST LIKE THE SPACE SHOOTER PROJECT! We debug.log to make sure its functioning properly. Then we set the main camera’s transform.position = your variable’s transform.position.
If you hop back into Unity you should see that all the Camera_Progression_Triggers have an empty slot on them called “myCamera” or whatever you named your variable. Since we set the Main Camera’s position to the variable’s position…. what exactly are we going to add to that slot? Well!
Drag the Camera_One Camera Progression Angle to the slot on the first Camera Progression Trigger, the Camera_Two Progression Angle to the Second Camera_Progression_Trigger, and so on and so on until you have connected all of them to their corresponding Camera Progression Triggers.
Now run your game. Make sure you click down close to the bottom of the screen to make sure Darren interacts with the first trigger. You should see your camera angle change! In the next article Ill talk about how to get the camera to follow your player’s position so that you can continue to progress through the level.