Documentation

Version 1.2.0

Thank you for purchasing Game Camera!

Table of contents

Table of contents

1 Introduction

2 Quick Start

3 Architecture

4 Camera Modes

4.1 Third Person Camera Mode

4.2 RPG Camera Mode

4.3 RTS Camera Mode

4.5 Dead Camera Mode

4.4 Orbit Camera Mode

4.6 LookAt Camera Mode

4.7 FPS Camera Mode

5 Input

5.1 Locking mouse cursor

5.3 Mobile

5.4 Input Configuration

5.5 Custom input (version 1.1.10)

6 Config

7 Camera effects

8 Camera events

9 Collision system

10 Character controller

10.1 Adding character to scene

10.2 Creating a navigation mesh

10.3 Replacing character with custom model

10.4 Dummy character controller

10.5 Final IK Character controller

10.6 Fighting with jitter

11 Multiplayer

12 Playmaker

13 Extras

14 FAQ

15 Support


1 Introduction

Game camera is a AAA camera solution for your game. This package contains 3rd person camera, RPG camera, RTS camera and more in professional quality you can see in today's AAA games. It comes with advanced configuration system, collision system for smoothest game experience and input system allowing you to play the game on keyboard with mouse, gamepad or mobile touch controls.

Why another Camera package?

There are already many camera packages on Asset Store, however except the UFPS there is still missing high quality asset of 3rd person, rts or rpg camera. The goal of this package is to create AAA camera solution for 3rd person, RPG and RTS camera games.

Mobile friendly

Game Camera package contains fully configurable input system for your touch device, you can create custom buttons, sticks and camera panel, more information in Mobile Input section.

Camera effects

This package contains system for creating various camera effects like earthquake, boss stomp, explosion and many others.

Camera events

Camera Events is a powerful system for triggering effects, changing camera modes, modifying camera configurations in runtime.

Collision system

This package contains highly sophisticated collision system for the smoothest game experience. Whether your character is walking inside small cave or running between obstacles the camera will always change smoothly without any hard jumps.

Character controller and extras

This package would never be possible without solid character controller. It is based on Unity Mecanim technology and all animation trees with source animations are included in the package. All the animations used are freely available on Asset Store.

Support and future work

My goal is to keep improving this package as much as possible. I will be adding more features and fixing bugs based on your feedback as I already do with my other assets Exploder and PrimitivesPro.


2 Quick Start

Adding Game Camera to my game

You already have some ready to play game and you want to replace your old camera system or you just want to start from scratch? Follow this simple guide to setup game camera:

Youtube video

0. Import the package, during installation you will be asked if you want to import InputManager.asset:

Select Yes (default option) if you want to use GameCamera input settings, this option is most recommended. Select No, if you already have your game input precisely configured and you don’t want to reconfigure it again.

If you select No, please read Input chapter, you will have to add camera controls manually.

1. Add GameCamera prefab to the scene Hierarchy, prefab is located in Assets/GameCamera/Prefabs.

2. Select CameraManager in GameCamera game object:

3. Assign your Unity main camera here

I

4. Select camera mode you wish to activate on start

Optional - 5. Add character controller from this asset (if you don’t have your own character)

Select CharacterController from prefabs and move it to scene hierarchy next to GameCamera game object.

In case of RTS or RPG camera you have to generate a navigation mesh in the scene otherwise the character won’t move. Please read more information in this chapter.

6. Assign camera target

Camera Target is your character, you can use your own or a character from this package (as described in previous step).

7. Select InputManager in GameCamera game object and choose proper Input Preset. (NOTE: this is handled automatically if you are using character controller from this asset)

Selecting Input Preset is necessary for correct camera controls. RPG camera should match RPG input preset, ThirdPerson camera should match ThirdPerson input preset, etc.

8. Done, you should be able to manipulate the camera in play mode.


3 Architecture

[enlarge]

As you can see from diagram, everything starts at CameraManager, which is the main singleton class of the asset. CameraManager contains a master update loop and updates every camera component.

CameraManager contains list of every CameraMode, which is a base class of game cameras like ThirdPersonCamera, RTSCamera, RPGCamera, LookAtCamera, OrbitCamera and DeadCamera.

Every  CameraMode contains a configuration, which can be adjusted in Unity inspector or in the game (EnableLiveGUI = true).

InputManager (CameraInput) is another singleton class. It handles all camera input. It means that CameraMode does not use Unity input at all, it communicates only with InputManager, which can be fully configured as well. CameraInput contains several input presets to match each camera mode: OrbitInput, ThirdPersonInput, RTSInput and RPGInput.

CameraCollision is another singleton object that calculates the correct position of camera view frustum inside the scene. Every CameraMode has access to CameraCollision and if needed it is calculated every frame.

EffectManager is another singleton object for running various camera effects. It is independent of CameraModes however updated by CameraManager, effect can be created anytime from anyplace.


4 Camera Modes

Camera Mode is a type of game camera, in this package there are 6 Camera Modes:

  1. Third person camera mode
  2. RTS camera mode
  3. RPG camera mode
  4. Orbit camera mode
  5. Look at camera mode
  6. Dead camera mode

Each camera mode can be set from CameraManager. Either from inspector:

Or from the code:

// activate third person camera mode

CameraManager.Instance.SetMode(Modes.Type.ThirdPerson);

// you can always get current camera mode

var mode = CameraManager.Instance.GetCameraMode();

Next subchapters will guide you through all of the CameraModes.


4.1 Third Person Camera Mode

Third Person Camera Mode (3rd camera) is a camera typical to action adventure games like series of Tombraider, GTA or Assasin’s creed. In this mode you can see the character from behind.

In 2nd chapter you can read how to quickly setup Third camera mode.

To configure 3rd camera select ThirdPersonCamera game object:

You should be able to see this in the inspector window:

There are 2 component scripts ThirdPersonConfig and ThirdPersonCameraMode. ThirdPersonConfig is the main configuration and we will explain it in more details. ThirdPersonCameraMode is a CameraMode script which contains several debug options and we can ignore them for now.

3rd Person Camera Configuration

There can be several configurations for each CameraMode. You can see complete list of configurations by clicking on “Configuration” list:

As you can see 3rd person camera has 4 different configurations. Each configuration can be activated from the code:

// activate "Default" configuration for current camera mode

var cameraMode = CameraManager.Instance.GetCameraMode();

cameraMode.SetCameraConfigMode("Default");

“Default” configuration is used for default state of your character like (stand, walk, run), “Crouch” configuration is used when the character is crouching, “Aim” when the character is aiming and “Sprint” is used while sprinting.

It means that for example your camera can have different FOV when the character is standing, aiming or sprinting. And you can create as many different configurations as you can, this gives you total freedom over character camera control.

It is your responsibility to select proper camera configuration, it usually happens in place with input controls of your character, for example you detect pressing a sprint button, at the same moment you should activate “Sprint” configuration.

When changing between configurations all parameters are smoothly interpolated in the proper transition time. You can change transition time by clicking on “Show transitions”:

For example changing from current configuration to “Aim” will take 0.15 [s], changing back to “Default” will take 0.5 [s].

Parameters explained

Parameter

Description

Default value

FOV

Field of view

60

Distance

Maximal distance of camera eye from the character, this distance can be changed (shortened) by the collision algorithm.

3

RotationSpeedX

Speed of horizontal rotation.

5

RotationSpeedY

Speed of vertical rotation.

5

RotationYMax

Maximal angle [deg] of vertical rotation.

70

RotationYMin

Minimal angle [deg] of vertical rotation.

-50

TargetOffset

Position offset from character pivot. Usually the character has pivot on the bottom (near the ground). For the best camera experience it is recommended to offset the pivot position to character head, typically (0, 1.6, 0), where 1.6 is the height of the character.

(0, 1.6, 0)

FollowCoef

Coefficient of following, it ranges from 0 to 10 and it is responsible of how much the camera should react on character movement. When set to 0 the camera never turns and the rotation always remains static. When set to non-zero value the camera starts to rotate as the character moves.

1

Spring

Spring coefficient. Imagine invisible spring connected to character on one end and the center of the screen on the other end. When set to 0, the character will never move from the center of the screen (maximal spring stiffness). Setting it to higher value will lower stiffness and you can see character running to the border of the screen followed slowly by the camera.

0.1

DefaultYRotation

Default vertical rotation [deg].

20

AutoYRotation

Coefficient of how fast the current vertical rotation should change to DefaultYRotation. When set to zero, it will never change, when set to 1 it will change quickly.

0.1

DeadZone

DeadZone is an ellipse around the character (screen center) where the character can move without moving the camera.

It can be used for filtering out small movement of the camera/character or for special camera mode. The values represent radiuses of the ellipse.

(0.1, 0.1)

Orthographic

Orthographic camera projection (this settings is equivalent to Unity camera Projection settings)

false

You can read more about configurations (saving/loading) in the Config chapter.


4.2 RPG Camera Mode

RPG Camera Mode is a camera typical to games with a character in the middle of the screen moving t mouse position, Diablo 3 is a good example of such a game.

In 2nd chapter you can read how to quickly setup RPG camera mode.

To configure RPG camera select RPGCamera game object:

You should be able to see this in the inspector window:

There are 2 component scripts RPGConfig and RPGCameraMode. RPGConfig is the main configuration and we will explain it in more details. RPGCameraMode is a CameraMode script which contains several debug options and we can ignore them for now.

RPG Camera Configuration

There can be several configurations for each CameraMode. You can see complete list of configurations by clicking on “Configuration” list:

As you can see RPG camera has 2 different configurations. Each configuration can be activated from the code:

// activate "Default" configuration for current camera mode

var cameraMode = CameraManager.Instance.GetCameraMode();

cameraMode.SetCameraConfigMode("Default");

“Default” configuration is used for outside game world, “Interior” configurations is used for moving inside buildings or caves.

It means that for example your camera can have different FOV when the character is outside or inside. And you can create as many different configurations as you can, this gives you total freedom over character camera control.

It is your responsibility to select proper camera configuration, for example changing configurations to “Interior” on some trigger close to door or cave entrance seems like a good idea.

When changing between configurations all parameters are smoothly interpolated in the proper transition time. You can change transition time by clicking on “Show transitions”:

For example changing from current configuration to “Interior” will take 1.0 [s], changing back to “Default” will take also 1.0 [s].

Parameters explained

Parameter

Description

Default value

FOV

Field of view

60

Distance

Default distance of camera eye from the character, this distance can be changed by zooming in/out.

15

DistanceMin

Minimal distance of camera, you cannot zoom-in beyond this point.

5

DistanceMax

Maximal distance of camera, you cannot zoom-out beyond this point.

20

ZoomSpeed

Speed of zooming.

5

EnableZoom

Boolean value to enable zooming.

true

DefaultAngleX

This is a default horizontal rotation angle [deg] around the character. It ranges from -180 to 180 degrees.

-135

EnableRotation

Boolean value to enable horizontal rotation.

false

AngleY

Vertical angle [deg] of the camera, final angle is calculated based on AngleZoomMin and current distance (zoom).

45

AngleZoomMin

Vertical angle [deg] of the camera for the maximal zoom-in. The more you zoom-in the more is vertical angle closer to this value.

35

TargetOffset

Position offset from character pivot. Usually the character has pivot on the bottom (near the ground).

(0, 1, 0)

DeadZone

DeadZone is an ellipse around the character (screen center) where the character can move without moving the camera.

It can be used for filtering out small movement of the camera/character or for special camera mode. The values represent radiuses of the ellipse.

(0.0, 0.0)

Spring

Spring coefficient. Imagine invisible spring connected to character on one end and the center of the screen on the other end. When set to 0, the character will never move from the center of the screen (maximal spring stiffness). Setting it to higher value will lower stiffness and you can see character running to the border of the screen followed slowly by the camera.

0.1

Orthographic

Orthographic camera projection (this settings is equivalent to Unity camera Projection settings)

false

You can read more about configurations (saving/loading) in the Config chapter.


4.3 RTS Camera Mode

RTS Camera Mode is a camera typical to games with many characters moving around, building structures, gathering resources and fighting enemies. Starcraft II is a good example of such a game.

In 2nd chapter you can read how to quickly setup RTS camera mode.

To configure RTS camera select RTSCamera game object:

You should be able to see this in the inspector window:

There are 2 component scripts RTSConfig and RTSCameraMode. RTSConfig is the main configuration and we will explain it in more details. RTSCameraMode is a CameraMode script which contains several debug options and we can ignore them for now.

RTS Camera Configuration

There can be several configurations for each CameraMode. You can see complete list of configurations by clicking on “Configuration” list:

As you can see RTS camera has only 1 configuration. Usually for RTS you will not need more than “Default” configuration but you can create a new one if you wish. Please read more in ThirdPersonCamera chapter to see how different configurations can be useful in your game.

Parameters explained

Parameter

Description

Default value

FOV

Field of view

60

Distance

Default distance of camera eye from the character, this distance can be changed by zooming in/out.

15

DistanceMin

Minimal distance of camera, you cannot zoom-in beyond this point.

5

DistanceMax

Maximal distance of camera, you cannot zoom-out beyond this point.

20

ZoomSpeed

Speed of zooming.

5

EnableZoom

Boolean value to enable zooming.

true

DefaultAngleX

This is a default horizontal rotation angle [deg] around the character. It ranges from -180 to 180 degrees.

-135

EnableRotation

Boolean value to enable horizontal rotation.

false

GroundOffset

Offset from the ground plane. By default the ground (game) plane is located in 0 (it is Y position of the floor in your game).

0

AngleY

Vertical angle [deg] of the camera, final angle is calculated based on AngleZoomMin and current distance (zoom).

70

AngleZoomMin

Vertical angle [deg] of the camera for the maximal zoom-in. The more you zoom-in the more is vertical angle closer to this value.

50

FollowTargetY

Boolean value to enable following target elevation. When the character goes up, the camera will also go up.

true

DraggingMove

Boolean value to enable dragging camera by mouse. if enabled you can click on the ground and drag it by mouse.

true

ScreenBorderMove

Boolean value to enable moving camera automatically when the mouse position hits border of the screen, this is very typical to RTS games. (Friendly note: this can be annoying when you are still developing the game, (moving mouse from game view to inspector view all the time) so I recommend to enable it when your game is finished).

true

ScreenBorderOffset

Offset in screen space pixels when to activate Screen Border Move.

10

ScreenBorderSpeed

Speed of moving camera with ScreenBorderMove

4

KeyMove

Boolean value to enable moving camera by keys (keyboard or gamepad)

true

MoveSpeed

Speed of moving camera with KeyMove

1

MapCenter

Center of the game map, this is used together with MapSize to determine borders of the game map. Camera will never go beyond the map.

(0, 0)

MapSize

Size of the game map, this is used together with MapCenter to determine borders of the game map. Camera will never go beyond the map.

(100, 100)

DisableHorizontal

Disable horizontal move.

false

DisableVertical

Disable vertical move

false

DragMomentum

Momentum of camera when the camera is swiped.

1.0

SoftBorder

Border on the map that camera will snap back.

5.0

Orthographic

Orthographic camera projection (this settings is equivalent to Unity camera Projection settings)

false

You can read more about configurations (saving/loading) in the Config chapter.


4.5 Dead Camera Mode

Dead Camera Mode is a special camera mode, it has only one purpose to highlight a death of the main character. It slowly rotates around the dead body.

 

In 2nd chapter you can read how to quickly setup Dead camera mode, however you will most likely activate this camera mode after your character die; and you will do it from script:

CameraManager.Instance.SetMode(Type.Dead);

To configure Dead camera select DeadCamera game object:

You should be able to see this in the inspector window:

There are 2 component scripts DeadConfig and DeadCameraMode. DeadConfig is the main configuration and we will explain it in more details. DeadCameraMode is a CameraMode script which contains several debug options and we can ignore them for now.

Dead Camera Configuration

There can be several configurations for each CameraMode. You can see complete list of configurations by clicking on “Configuration” list:

As you can see Dead camera has only 1 configuration. Usually for Dead camera you will not need more than “Default” configuration but you can create a new one if you wish. Please read more in ThirdPersonCamera chapter to see how different configurations can be useful in your game.

Parameters explained

Parameter

Description

Default value

FOV

Field of view

60

Distance

Distance from character.

4

RotationSpeed

Speed of rotation around the dead body, negative value will result in opposite rotation.

0.5

Angle

Vertical angle [deg] of camera.

50

TargetOffset

Position offset from character pivot. Usually the character has pivot on the bottom (near the ground).

(0, 1, 0)

You can read more about configurations (saving/loading) in the Config chapter.


4.4 Orbit Camera Mode

Orbit Camera Mode is not really a game mode. It was inspired by Unity Editor scene camera. You can do pretty much the same as Unity scene camera - pan, rotate or zoom.

In 2nd chapter you can read how to quickly setup Orbit camera mode.

To configure Orbit camera select OrbitCamera game object:

You should be able to see this in the inspector window:

There are 2 component scripts OrbitConfig and OrbitCameraMode. OrbitConfig is the main configuration and we will explain it in more details. OrbitCameraMode is a CameraMode script which contains several debug options and we can ignore them for now.

Orbit Camera Configuration

There can be several configurations for each CameraMode. You can see complete list of configurations by clicking on “Configuration” list:

As you can see Orbit camera has only 1 configuration. Usually for Orbit camera you will not need more than “Default” configuration but you can create a new one if you wish. Please read more in ThirdPersonCamera chapter to see how different configurations can be useful in your game.

Parameters explained

Parameter

Description

Default value

FOV

Field of view

60

ZoomSpeed

Speed of zooming.

2

RotationSpeedX

Speed of horizontal rotation.

5

RotationSpeedY

Speed of vertical rotation.

5

RotationYMax

Maximal angle [deg] of vertical rotation.

50

RotationYMin

Minimal angle [deg] of vertical rotation.

-50

PanSpeed

Speed of camera panning. You can pan camera by mouse or gamepad.

1

DisablePan

Boolean value to disable panning.

false

DisableZoom

Boolean value to disable zoom.

false

DisableRotation

Boolean value to disable rotation.

false

TargetInterpolation

Speed of moving camera to a new target. You can reset the camera target by double-clicking on middle mouse button, the camera target will be moved to the mouse position.

0.5

Orthographic

Orthographic camera projection (this settings is equivalent to Unity camera Projection settings)

false

You can read more about configurations (saving/loading) in the Config chapter.


4.6 LookAt Camera Mode

LookAt Camera Mode is a special camera mode. It is a static camera mode, where you can specify position and target where the camera should be. You can smoothly change  between targets.

 

In 2nd chapter you can read how to quickly setup LookAt camera mode, however you will most likely activate this camera mode from the script:

// activate look at camera mode

var mode = CameraManager.Instance.SetMode(Type.LookAt);

// look at random point in 2 second from current position

mode.LookAt(Random.insideUnitSphere*10, 2.0f);

// look from random point to zero point in 0.5 seconds

mode.LookAt(Random.insideUnitSphere*10, Vector3.zero, 0.5f);

// look from random point to current position immediately

mode.LookFrom(Random.insideUnitSphere*10, 0.0f);

To configure LookAt camera select LookAtCamera game object:

You should be able to see this in the inspector window:

There are 2 component scripts LookAtConfig and LookAtCameraMode. LookAtConfig is the main configuration and we will explain it in more details. LookAtCameraMode is a CameraMode script which contains several debug options and we can ignore them for now.

LookAt Camera Configuration

There can be several configurations for each CameraMode. You can see complete list of configurations by clicking on “Configuration” list:

As you can see LookAt camera has only 1 configuration. Usually for LookAt camera you will not need more than “Default” configuration but you can create a new one if you wish. Please read more in ThirdPersonCamera chapter to see how different configurations can be useful in your game.

Parameters explained

Parameter

Description

Default value

FOV

Field of view

60

InterpolateTarget

Boolean value to enable interpolating of camera target positions, if disabled interpolating of camera target rotations (quaternions) will be used.

true

Orthographic

Orthographic camera projection (this settings is equivalent to Unity camera Projection settings)

false

You can read more about configurations (saving/loading) in the Config chapter.

4.7 FPS Camera Mode

FPS Camera Mode is a camera typical to first person shooter games like Call of duty. This mode is not aimed to be fully featured like UFPS, it is here to support other game cameras in situations where it is necessary to switch to FPS mode in the game.

In 2nd chapter you can read how to quickly setup FPS camera mode.

To configure FPS camera select FPSCamera game object:

You should be able to see this in the inspector window:

There are 2 component scripts FPSConfig and FPSCameraMode. FPSConfig is the main configuration and we will explain it in more details. FPSCameraMode is a CameraMode script which contains several debug options and we can ignore them for now.

FPS Camera Configuration

There can be several configurations for each CameraMode. You can see complete list of configurations by clicking on “Configuration” list:

As you can see FPS camera has 2 different configurations. Each configuration can be activated from the code:

// activate "Default" configuration for current camera mode

var cameraMode = CameraManager.Instance.GetCameraMode();

cameraMode.SetCameraConfigMode("Default");

“Default” configuration is used for default character position in stand, “Crouch” configurations is used for character in crouch.

It means that for example your camera can have different FOV when the character is standing or crouching. And you can create as many different configurations as you can, this gives you total freedom over character camera control.

It is your responsibility to select proper camera configuration, for example changing configurations to “crouch” on some game input seems like a good idea.

When changing between configurations all parameters are smoothly interpolated in the proper transition time. You can change transition time by clicking on “Show transitions”:

For example changing from current configuration to “Interior” will take 1.0 [s], changing back to “Default” will take also 1.0 [s].

Parameters explained

Parameter

Description

Default value

FOV

Field of view

60

RotationSpeedX

Speed of horizontal rotation.

5

RotationSpeedY

Speed of vertical rotation.

5

RotationYMax

Maximal angle [deg] of vertical rotation.

50

RotationYMin

Minimal angle [deg] of vertical rotation.

-50

TargetOffset

Offset from the character (Target) pivot, by default the pivot is located between character feets.

(0, 2, 0)

HideTarget

Boolean value to disable target (character) visibility

true

Orthographic

Orthographic camera projection (this settings is equivalent to Unity camera Projection settings)

false

You can read more about configurations (saving/loading) in the Config chapter.


5 Input

In this chapter we will introduce InputManager and explain how to configure camera controls.

InputManager is a game object (and script component) inside GameCamera object:

Input manager is used for detecting input from various devices like keyboard, gamepad, mouse and touch device. It unites PC and Mobile controls together under one API. There are currently 13 game camera input controls available.

These controls are used mainly for camera controls. However you can also use them for controlling the character.

Input Name

Description

Pan

Camera panning - used only for Orbit mode.

Zoom

Zooming - used for RTS, RPG and Orbit mode.

Rotate

Rotating camera around, used for every mode.

Move

Moving of the camera, this is used for most of camera modes and also for moving the character.

Reset

Trigger used for resetting camera position or resurrecting the character.

Aim

Trigger used for aiming of character.

Fire

Trigger used for firing of character.

Crouch

Trigger used for crouching of character.

Walk

Trigger used for walking of character.

Sprint

Trigger used for sprinting of character.

Jump

Trigger used for jumping of character.

Die

Trigger used for dying of character (debugging purposes).

WaypointPos

Position in the game, typically mouse position in world space, where the character should go, this is used with RTS and RPG camera modes.

You can access any of these controls from the script:

// get status of fire input toggle

// second parameter is default value if not pressed

var fireInput = InputManager.Instance.GetInput(InputType.Fire, false);

// get status of move vector

// second parameter is default value if not pressed

var move = InputManager.Instance.GetInput(InputType.Move, Vector2.zero);

InputManager contains several input presets for most of CameraModes:

[for script reference please see Assets\GameCamera\Scripts\Input\*]

Each preset contains a definition of controls that suits best to its belonging CameraMode. However there is nothing to stop you from using for example ThirdPersonCameraMode and RPGInput preset, but you will just see that some controls are not responding.

You can choose InputPreset from inspector:

Of from the script:

// select input preset for RTS mode

InputManager.Instance.SetInputPreset(InputPreset.RTS);

Disabling Input

In some cases it can be useful to disable Camera input or input of the character controller. One of the example would be clicking on GUI button on the screen, when you click you don’t want to move the camera or character. You can disable input from the script:

// disable input for camera

InputManager.Instance.EnableInputGroup(InputGroup.CameraMove, false)

// disable input for character controller

InputManager.Instance.EnableInputGroup(InputGroup.Character, false)

// disable input for all game camera input

InputManager.Instance.EnableInputGroup(InputGroup.All, false)

// enable input back

InputManager.Instance.EnableInputGroup(InputGroup.All, true)


5.1 Locking mouse cursor

By default the mouse cursor is unlocked in play mode and you can see it’s moving on the screen, however for 3rd person camera you would rather want to hide and lock the cursor so you can move the camera. For this reason there is a cursor locking script located in InputManager game object:

As you can see you can set up locking and unlocking key or lock the cursor immediately.


5.3 Mobile

This package contains fully configurable mobile controls for touch devices. To enable mobile input, you have to first enable MobileInput in InputManager:

and enable MobileControls game object:

Then you should see default buttons in the game view:

Default mobile buttons

These are default mobile buttons, you can remove them, add more, change texture, position or size in the settings as we will explain later.

There are 4 types of mobile controls:

Stick is a touch simulation of a gamepad stick, usually it is used for moving the character.

Stick

CameraPanel is an invisible part of the touch screen (left half or right half) and it is used for moving the camera.

CameraPanel

Zoom area is an invisible part of the touch screen (defined by x, y, width and height) and it is used for zooming the camera (pinch gesture).

Configuration

Let’s look at the MobileControls inspector:

There are 3 main sections, Left panel, Right panel and Buttons.

Left panel and Right panel are in other words two sides of the screen, left side and right side. It means that each side can be configured independently, you can have Stick on right side and Camera panel on left side or opposite. Or you can have two Sticks or nothing at all.

Buttons section is a place where you can create as many buttons as you wish, assign custom texture and place them properly on the screen.

Parameters explained

Stick

Description

Default

StickAxis0*

Name of axis for horizontal movement, the name should correspond to the same name as described in Unity InputManager, more information in Input Configuration section.

Horizontal

StickAxis1*

Name of axis for vertical movement, the name should correspond to the same name as described in Unity InputManager, more information in Input Configuration section.

Vertical

CircleSize

Size of stick circle.

200

HitSize

Size of the small point inside the big circle.

32

ControlCircle

Texture of stick circle.

-

HitPoint

Texture of hit point.

-

HideGUI

Hide the stick.

false

Camera panel

Description

Default

CameraAxis0*

Name of axis for horizontal camera movement, the name should correspond to the same name as described in Unity InputManager, more information in Input Configuration section  (next paragraph).

Horizontal_R

CameraAxis1*

Name of axis for vertical camera movement, the name should correspond to the same name as described in Unity InputManager, more information in Input Configuration section.

Vertical_R

Sensitivity Horizontal

Sensitivity of horizontal axis.

0.2

Sensitivity Vertical

Sensitivity of vertical axis.

0.1

HitPoint

Texture of hit point.

-

Button

Description

Default

Name

Name of the button, the name should correspond to the same name as described in Unity InputManager, more information in Input Configuration section (next paragraph).

-

X

Horizontal position of the button in screen coordinates, the position remains relative to screen size.

-

Y

Vertical position of the button in screen coordinates, the position remains relative to screen size.

-

Width

Width of the button in percent, the size remains relative to screen size.

-

Height

Height of the button in percent, the size remains relative to screen size.

-

Preserve texture ratio

Calculate width and height automatically using texture size.

true

Toggle

If true, button will remain pressed on first touch and un-pressed on second touch, otherwise it will be a standard button.

false

HideGUI

Hide the button.

false

Default texture

Button texture

-

Pressed texture

Texture of pressed button.

-

Zoom area

Description

Default

Name

Name of zoom area, should be “Zoom” for proper working.

Zoom

X

Beginning of the horizontal zoom area in screen coordinates.

0

Y

Beginning of the vertical zoom area in screen coordinates.

0

Width

Width of the zoom area in percent of the screen.

0

Height

Height of the zoom area in percent of the screen.

0

Sensitivity

Sensitivity of the pinch gesture

1

ReverseZoom

Reverse pinch gesture (from zoom in to zoom out)

False

HideGUI

Hide the helper UI

False

Mobile input presets

There are several ready to go mobile input presets, you can use them by clicking on Load button in Presets section:

The presets are located in Assets/GameCamera/Content/MobileResources/layouts/. This directory is a default directory and should be shown by default.


5.4 Input Configuration

To configure camera input you have to use standard Unity Input Manager. This package comes with already predefined InputManager.asset file and you can choose to use it during installation process. It has been configured and tested with keyboard, mouse and X360 gamepad.

Predefined GameCamera InputManager looks like this

Important note:

Names of Mobile controls (stick, camera panel, buttons) must correspond to names described in the image above.

If you have accepted InputManager during installation you shouldn’t have any problems. Feel free to configure this input as you wish.

If you have selected No during installation you will have to add all input controls manually, otherwise you will see this error in play mode:

It means that you have to add all missing inputs, button names and axis to match the image of InputManager above.

Note: You can always activate the installation window again by clicking on GameCamera menu and import the InputManager.

To help you with adding missing inputs you can backup your current InputManager.asset (located in ProjectSettings folder) and copy the GameCamera InputManager from Assets/GameCamera/Content/InputManager/InputManager.a (you will have to rename the extension to .asset).

For full configuration reference see this image.


5.5 Custom input (version 1.1.10)

GameCamera can be used in combination with other third party input libraries, for example EasyTouch. There are just few steps needed to enable custom input:

  1. Select Custom input preset in input manager:

customInput.png

  1. In case you are using CharacterController from this asset, disable AutoInput in Player component script, otherwise Player will select input based on the camera mode.

customInputAutoInput.png

  1. Now go to your custom script where you receive events from the input library and put this line in the beginning of update loop:

void Update()

{

  // invalidate camera input before the update

  RG_GameCamera.Input.InputManager.Instance.ResetInputArray();

  //...

}

  1. Now every time you receive input from your input library pass it to CustomInput class:

public void OnPitchIn(gesture g)

{

  // get custom input preset

  var customInput =   RG_GameCamera.Input.InputManager.Instance.GetInputPresetCurrent() as CustomInput;

  if (customInput)

  {

    // apply zoom to camera input

    customInput.OnZoom(g.deltaPitch);

  }

}

For full script reference of custom input class, please see public methods in class:

CustomInput.cs

You can find script of using above in example script:

GameCamera/Scipts/Examples/TestCustomInput.cs


6 Config

As we described earlier in CameraMode chapter, every CameraMode has its own config script with parameters, multiple configurations and transition settings.

Serialization

Everytime you change a parameter you will notice that Save button turns red. It is a warning that config has changed but hasn’t been saved. If you don’t press Save button the config will be discarded next time you run the game.

The same is for changing parameters in play mode, every time you make a change save it otherwise you will lose your settings back in editor mode.

Using Save as (or Load new) you can save (load) config file to any location on the disk.

Default location for all config files is in Assets/GameCamera/Resources/Config/*.

Changing camera modes configurations

Usefulness of multiple configurations per camera mode was already discussed in CameraMode chapter. If you want to create a new configuration or remove the old one you can do it directly from the inspector:

You can create as many configurations as you want, but all the names must be unique, you cannot have 2 configurations with the same name.

You can remove any configuration except Default.


7 Camera effects

This asset contains also a library of several camera effects that can be used to enhance feeling from your game.

Effects are managed by Effect Manager, another game object inside Game Camera:

As you can see there are 8 camera effects:

Effect

Description

Earthquake

Earthquake, shaking of the camera for a while.

Yes

Moving of the camera up and down to say yes.

No

Moving of the camera left and right to say no.

FireKick

Used with third person camera to kick a camera on fire.

Stomp

Stomp of a boss, shaking of the ground

Fall

Fall of the camera, used with third person camera after fall or jump.

Explosion

Explosion near player, makes short camera shake.

SprintShake

Shaking camera during sprinting.

You can configure each effect by public parameters directly in the inspector.

Running the effect

There are 2 ways to run the effect:

1. From the code:

// create and play boss stomp shake

var stomp = EffectManager.Instance.Create(Effects.Type.Stomp);

stomp.Play();

2. By creating camera event. Please read camera event chapter for more information.


8 Camera events

Camera event is a game object with box collider that triggers when your character enters it. On that trigger you can change camera settings:

To create camera event just drag and drop CameraEvent prefab to the scene hierarchy:

Then you should see this in the inspector:

And in Scene view you should see the box collider:

Important step: To make the trigger working with your character, you have to add CameraTrigger script component to your character object.

Now you should be able to run camera events whenever your character enters the box collider.

Configuration

Next tables describes every camera event settings:

Events

Effects

Camera effect

Run camera effect on trigger enter.

Events

Config Param

Config parameter name

Name of the parameter from current camera mode configuration, for example if you want to change FOV in third camera mode, you have to write “FOV”, you can find other names of all parameters in camera mode chapter.

Type

Type of parameter, it can be bool, float, string, etc.

Config param value

Value of parameter, depending on type, it can be true, 1.0f, “text”, etc.

Restore on exit

Boolean value to enable restoring of the camera parameter on trigger exit. If it is false, the parameter will stay changed permanently.

Events

Config Mode

Config mode name

Name of the camera mode configuration you want to set up, for example RPG camera contains “Default” and  “Interior” configuration. Your character is about to enter the cave and you wish to change configuration to “Interior”. Just type the name “Interior” in this field and you are done.

Restore on exit

Boolean value to enable restoring of the camera mode configuration on trigger exit. If it is false, the configuration will stay there permanently.

Events

Look At

From

Select game object, its position will be used as an eye of the camera.

To

Select game object, its position will be used as a camera target.

Time

Time [s] to change camera to the LookAt position.

Restore on exit

Boolean value to enable restoring of the camera back to its original camera mode before entering the trigger. If set to false, camera will stay in look at permanently.

Events

Custom Message

GameObject

Select game object which will be used as a message recipient. It should contain a script component with the name of the custom function.

Function name on Enter

Name of the function to be called on trigger enter.

Function name on Exit

Name of the function to be called on trigger exit.


9 Collision system

Collision system is a set of algorithms that calculate camera position and distance in a way that camera does not collide with any objects in the scene. This package contains 3 different algorithms which can be configured from the inspector.

Simple collision algorithm

The fastest collision algorithm. It contains only a single raycast which is placed in direction of the camera. If the raycast hits an obstacle it moves the camera quickly to the character. Results are good but not very smooth. You can use this algorithm if the performance really matters.

Simple collision algorithm

Spherical collision algorithm

This algorithm is originally from Unity Samples package, algorithm is very similar to Simple one, only the sphere is used instead of ray. Because of the nature of sphere cast, this algorithm is more expensive.

Spherical collision algorithm

Volumetric collision algorithm

Volumetric algorithm is more advanced, it uses a similar approach as the previous one however instead of sphere cast the collision volume is constructed from set of raycasts and tested against the scene. This algorithm provides the smoothest way of moving the camera away from obstacles. The performance of this algorithm is similar to the Spherical one.

Volumetric collision algorithm

Ignoring the collision

Sometimes it is better to ignore the collision completely or just use a transparency. There are two ways of doing this:

  1. Use a tag. Tag an object to notify collision algorithm about the ignored (transparent) object. See next section for tag names.

  1. Use a script component

Important note: Transparency works only with Transparent material with alpha.

Configuration

Configuring camera collision is similar to configuring camera mode. Select the CameraCollision game object in scene hierarchy to access the inspector window:

Parameter

Description

Default value

MinDistance

Minimum distance of camera eye to the character. If you set this to 0, camera will go “inside” your character.

0.5

ReturnSpeed

Speed of returning camera eye back to default distance when no obstacle is detected.

0.01

ClipSpeed

Speed of moving camera to the character when the obstacle is detected.

0.1

IgnoreCollisionTag

Use this tag on objects to ignore camera collision.

“IgnoreCameraCollision”

TransparentCollisionTag

Use this tag on objects to apply transparency instead of collision algorithm.

“CameraTransparent”

TargetSphereRadius

Radius of a sphere for testing side collision.

0.5

TargetClipSpeed

Speed of moving camera to the character when the obstacle is detected from the side. In this case the camera is moved to direction of character (above his head)

0.1

ReturnTaretSpeed

Speed of moving returning camera back to default when no obstacle is detected.

0.4

SphereCastRadius

Radius of spherecast in case of Spherical algorithm.

0.5

SphereCastTolerance

Size of SphereCastRadius that is ignored during collision.

0.1

CollisionAlgorithm

Type of collision algorithm, can be Simple, Spherical, Volumetric

Volumetric

ConeRadius

In case of Volumetric CollisionAlgorithm, this value represents 2 radiuses of a collision cone.

(0.5, 0.5)

ConeSegments

In case of Volumetric CollisionAlgorithm, this value represents number of segments of collision cone (each segment will represent 1 raycast)

10

HeadOffset

Position above the character head, this value is used as a camera position in case of the collision near the character.

1.8


10 Character controller

This chapter contains detailed information character controllers from this package. The character controller is based on Unity Sample Assets package, with many added features:

All animations used are freely available on asset store, mostly from Unity sample assets, raw mocap data and from Bootcamp.

Mecanim Animation tree.

10.1 Adding character to scene

As already described in Quick start you can create a character controller object by drag and dropping CharacterController prefab to scene hierarchy.

Don’t forget to add also CharacterSFX object to the scene. This object contains shooting particles, health bar, cross-hair, waypoint marker and shooting sound.

10.2 Creating a navigation mesh

Update 1.1

Using of navigation mesh can be disabled (for example for performance reasons), character will move in RPG or RTS mode directly to the mouse position. To disable navmesh, please locate the file AIController.cs and comment the macro in the beginning like this:

// #define USING_NAVMESH

Navigation mesh (navmesh) is necessary if you want to move the character in RPG or RTS camera mode. Generating navmesh is very simple, open navigation window (Window -> Navigation) and bake the scene (you might have to mark static objects as static). Please read more information in Unity documentation.

After baking your scene should like this:

Navigation mesh of a sample scene.

10.3 Replacing character with custom model

If you like the character controller from this package and you just want to replace the model, you can do it very easily. All you have to do is open the character controller hierarchy, remove or deactivate the old model and add a new one.

Remove old deactivate old model

Adding a new model

10.4 Dummy character controller

This package also contains a dummy character controller - a moving capsule without animations. It comes with a minimalistic script and you can use it for building your character controller from scratch.

Dummy character prefab

Dummy character

10.5 Final IK Character controller

GameCamera has been tested with Final IK character controller. Setup is slightly different from built-in character controller. Here’s the guide:

  1. Use Final IK AnimationController as CameraTarget:

    final-ik target.jpg

  1. Set position filter to 0 in ThirdPersonCamera game object:

    finalIK.png

  1. Turn on smooth physics on Final IK character controller (by default) for the smoothest experience.

10.6 Fighting with jitter

When using GameCamera some users can experience a jitter of the character controller, this jitter is more apparent when using spring in ThirdPersonCamera mode settings. The jitter is caused by a different frequency of character rigid body which camera tries to follow and a frequency of the camera update. In general physics system has smaller amount of updates (fixed time steps) than standard script component. This problem can’t be fixed by updating GameCamera on fixed time step because it would bring new problems like jitter of camera with world. The best solution here is to split character controller into two parts - physics and renderer. The physics object have the rigid body and updates on fixed time step, the renderer object contains the mesh and it will lerp to the rigid body object.

GameCamera comes with helper script that can be used in your Character controller, following example will show how to use it with built-in character controller:

  1. Split your character controller into two parts, most of the controllers are already done that way. First parent object will contain rigid body and all control scripts, child will contain mesh and renderer.

    jitter01.png

    In this example
    CharacterController contains rigid body and all control scripts, swat object contains additional children with mesh and renderers.

  2. Set RigidBody interpolation mode to Interpolate. This will add some internal smoothing to the rigid body movement.

    jitter02.png

  3. Add SmoothFollowPhysics script component to the child object (swat), this script will be following the parent physics object smoothly in time.

    jitter03.png

  4. Set the child object (swat) as GameCamera target, this step is important. GameCamera will be following the child object and not the physics object.

    jitter04.png

This setup will eliminate most of the jitter problems in character controllers. Use this setup only with 3rd person controller setup, when used with RPG/RTS mode it can cause problems when combining with navigation agents.


11 Multiplayer

This section contains information about setting up the game camera for multiplayer games.

Important note: Game camera does not contain any multiplayer code like sending or receiving data between client and server, synchronization, etc. This area is usually covered by one of the networking systems like Photon or Unity networking. Game camera only contains support scripts to help you build your multiplayer game.

Steps to build your multiplayer game:

  1. In editor create Game Camera (using the prefab), this object will be there during the whole game life-time. There is no need to destroy or instantiate it again.
  2. On the game start you can set the Game camera mode to None, LookAt or set to your player character (ThirdPerson, RTS, RPG) in case your player is always spawned on game start.

// example of setting camera mode on game start

// set camera to none, will look at default position

CameraManager.Instance.SetMode(Modes.Type.None);

  1. When your player is de-spawned/deleted from the scene, set the Game camera mode back to None or LookAt as in previous example.

  1. When your player is spawned to the scene, re-set the Game camera target and  camera mode:

// spawn the player

player = Instantiate(CharacterControllerPrefab, pos, Quaternion.identity) as GameObject;

// reset a new camera target

CameraManager.Instance.SetCameraTarget(player.transform);

// start 3rd camera with a new player

CameraManager.Instance.SetMode(Type.ThirdPerson);

Important step for remote Players:

  1. In case of spawning remote player, don’t forget to set Remote flag to true, otherwise you will control the remote player by the local player’s input.

// spawn remote player

remotePlayer = Instantiate(CharacterControllerPrefab, pos, Quaternion.identity) as Human;

// set remote flag

remotePlayer.Remote = true;

Examples

There are two example scripts and one Multiplayer scene:

multak.jpg

Multiplayer example scene with players switching script.

multakSpawnDespawn.jpg

Example script for spawning and de-spawning character controller.


12 Playmaker

GameCamera supports several Playmaker actions:

To enable Playmaker actions please locate directory Scripts/Playmaker and in each file uncomment the line with macro to be like this:

#define PLAYMAKER.

In Playmaker editor you can find all these actions in section Camera.


13 Extras

This chapter contains information about prefabs and scripts that were created for the demo, you can use them if you like them.

Healthbar

Healthbar object is located in CharacterSFX prefab and is activated automatically for game camera character controller. It contains a simple script for setting health, you can access if from public API:

// set 50% of health

Extras.HealthBar.Instance.SetHealth(50);

Waypoint Projector

Waypoint projector is a projector used for marking a position in the scene. It is used with RTS and RPG camera mode. Projector object is located in CharacterSFX prefab and is activated automatically for game camera character controller.

Zombie

Zombie is an animated character with own Mecanim tree and simple AI attacking the player. All animations and model are freely available on asset store (here and here). To use the zombie, just drag and drop the zombie prefab to the scene:

[Assets/GameCamera/Content/Demo/Zombie/ZombieCharacterPack/zombie.prefab]

Make sure you set up the navigation mesh as described in this chapter, otherwise the zombie won’t move. And be careful, it will try to kill you!

Cave worm

Cave worm is an animated creature with simple AI attacking the player. All animations and model are freely available on asset store (here). To use the cave worm, just drag and drop the cave worm prefab to the scene:

[Assets/GameCamera/Content/Demo/FT_CaveWorm/_Prefab/CaveWorm.prefab]

Make sure you set up the navigation mesh as described in this chapter, otherwise the worm won’t move. And be careful, cave worm is very aggressive!

MedKit

medkit.jpg

MedKit is an object that you can pick up and increase your HP. You can put the MedKit to the scene by drag and dropping the MedKit prefab:

[Assets/GameCamera/Prefabs/MedKit.prefab]


14 FAQ

  1. Q: The input doesn’t work, I see input related errors in the console after installation.

A: Please make sure you have installed InputManager.asset file, you should see the installation dialog during the import, you can always open the installation dialog from Unity Editor menu (Window - GameCamera - Installer).

In case you still cannot install the file, try to copy the file manually:

1. Locate the file in GameCamera/Content/InputManager/InputManager.install (InputManager.a in earlier version)

2. Copy the file to ProjectSettings directory in your project folder.

3. Rename the file to InputManager.asset (this will overwrite the current one).

  1. Q: Camera doesn’t seem to rotate and I see the mouse cursor.

A: The cursor must be locked in order to rotate the camera, please look at InputManager GameObject in GameCamera hierarchy, there is a CursorLocking script with cursor settings. See this chapter.

  1. Q: I would like to spawn and despawn the character controller in multiplayer game.

A: Please look at the example script in Scripts/Examples/SpawnDespawn.cs.

  1. More Q&A will come, I will be updating this section...


15 Support

If you have any questions, feedback, bug reports or feature suggestions, you can always send me an e-mail to:

gamesreindeer@gmail.com

Or you can write to Unity forum:

http://forum.unity3d.com/threads/released-game-camera.252261/