Camera Setup

The kits come with vehicle camera prefabs already set up that you can replace your camera with to get started.

  1. For the Space Combat Kit, drag the VehicleCamera_SCK prefab into the scene.

  2. For the Mech Combat Kit, drag the VehicleCamera_MCK prefab into the scene.

Creating A Vehicle Camera

To create your own vehicle camera instead, add a Vehicle Camera component to your camera and customize the inspector settings.

Setting Up Input

To add camera input to the player, add a PlayerInput_InputSystem_CameraControls component somewhere in the player hierarchy.

To change the input bindings, look for the General Input object in the Project tab and double click it. This will open Unity's Input System editor where you can change the camera input bindings. By default, you can cycle camera views back and forth with the brackets keys [ ].

If you want to change camera views in your own script, use the following code:

// Set a camera view
myVehicleCamera.SetView(myCameraView);

// Cycle through camera views forward
myVehicleCamera.CycleCameraView(true);

// Cycle through camera views backward
myVehicleCamera.CycleCameraView(false);

Enabling/Disabling Camera Control

Sometimes you may want to disable the vehicle camera's control over itself, for example to run a cutscene or control it with a different script.

Simply uncheck the Camera Control Enabled checkbox in the Vehicle Camera inspector to disable it, or check it to enable it again. You can also do it in code:

// Disable the vehicle camera's control of itself
myVehicleCamera.CameraControlEnabled = false;

// Enable the vehicle camera's control of itself
myVehicleCamera.CameraControlEnabled = true;

Camera Collisions

Especially in third person view, the camera could clip behind some meshes and obstruct the view of the player.

To avoid this, you can check the Camera Collision Enabled checkbox in the inspector of the Vehicle Camera component.

Follow The Player

To make sure the vehicle camera follows the player in whatever vehicle they are in:

  1. Make sure there is a Game Agent Manager component in the scene (it is already part of the Scene Objects prefab).

  2. Check the Link To Game Agent Manager checkbox in the inspector of the Vehicle Camera component.

Setting The Vehicle To Follow

To manually set a different vehicle to be followed by the camera in code, use following code:

// Follow a different vehicle
myVehicleCamera.SetVehicle(someOtherVehicle);

Camera Controllers

The vehicle camera comes with a built in camera controller as well as the option to add custom camera controllers of your own.

Space Combat Kit

The Space Combat Kit includes two camera controllers, for space fighters (Space Fighter Camera Controller) and capital ships (Capital Ship Camera Controller).

These are already added to the VehicleCamera_SCK prefab in the kit. To set these up yourself, just add one or both of these components anywhere in your vehicle camera's hierarchy.

Be sure that the correct Vehicle Class is assigned in the inspector of each of your vehicles' Vehicle components, and also added to the Compatible Vehicle Classes list in the respective camera controller components.

Mech Combat Kit

The Mech Combat Kit uses the Vehicle Camera's built-in camera controller, so no additional camera controllers are required.

Creating Camera Controllers

There are several key functions you can override when extending the Vehicle Camera Controller base class to create your own camera behavior:

  • Initialize: called when the camera starts following a vehicle, to see if the camera controller should be started. Add code to check if the camera controller is relevant for the vehicle.

  • Camera Controller Update: called in Unity's Update loop.

  • Camera Controller Fixed Update: called in Unity's Fixed Update loop, typically used when the camera is following an object with a rigidbody to prevent jitter.

  • Camera Controller Late Update: Called in Unity's Late Update loop, typically used when the camera is following an object without a rigidbody.

Free Look (Gimballed Camera)

The Vehicle Camera prefab in the kit is already gimballed, so check that for reference.

You can set up your own gimballed camera to be able to look around (rotate in any direction) by completing the following steps (once you've already created a vehicle camera).

  1. Add a Gimbal Controller component to the vehicle camera.

  2. Create a new game object as a child of the vehicle camera, rename it to 'Horizontal Pivot', and set it as the Horizontal Pivot in the inspector of the Gimbal Controller component.

  3. Create a new game object as a child of the horizontal pivot, rename it to 'Vertical Pivot', and set it as the Vertical Pivot in the inspector of the Gimbal Controller component.

  4. Add the camera as a child of the vertical pivot (not the vehicle camera's root transform).

  5. Add a PlayerInput_InputSystem_CameraFreeLookControls component to the Player's hierarchy.

If you are still unsure of anything, check the provided vehicle camera prefab for reference.

Last updated