This guide explains how to configure and use the CameraController
script to manage multiple Cinemachine virtual cameras, implement camera shake, and dynamically adjust the field of view (FOV) based on bike speed in Unity.
Public Variables Explained
- cameras:
- Description: Array of Cinemachine virtual cameras.
- Purpose: Used to switch between different camera views.
- bikeController:
- Description: Reference to the
ArcadeBikeControllerPro
script attached to your bike GameObject.
- Purpose: Accesses bike-related data such as speed to control camera effects.
- speedThresholdForShake:
- Description: Speed threshold above which the camera shake effect starts.
- Purpose: Determines the speed at which the camera shake begins.
- shakeAmplitude:
- Description: Amplitude of the camera shake effect.
- Purpose: Controls the intensity of the camera shake.
- shakeFrequency:
- Description: Frequency of the camera shake effect.
- Purpose: Controls the frequency of the camera shake.
- switchCameraKey:
- Description: Key to switch between different cameras.
- Purpose: Allows the user to switch camera views during gameplay.
- minFOV:
- Description: Minimum camera FOV value.
- Purpose: Sets the lower limit for the camera's field of view.
- maxFOV:
- Description: Maximum camera FOV value.
- Purpose: Sets the upper limit for the camera's field of view.
- FOV_smoother:
- Description: Smoothing factor for the camera FOV value.
- Purpose: Controls how smoothly the camera's FOV transitions between values.
How to Use the Camera Controller
1. Assign the Script
- Attach the
CameraController
script to an empty GameObject in your scene or to an existing manager GameObject.
2. Configure Public Variables
- cameras: Drag and drop your
CinemachineVirtualCamera
instances into this array. You can create multiple CinemachineVirtualCamera
GameObjects in your scene and assign them here.
- bikeController: Drag and drop the
ArcadeBikeControllerPro
component from your bike GameObject into this field.
- speedThresholdForShake: Set the speed at which the camera shake effect starts.
- shakeAmplitude: Set the intensity of the camera shake.