TransitionCamera.gif

Camera Controllers & Fluid In-Game Camera Transitions

What I aimed to do during this project was to reproduce 3 different well-established camera styles and make transitions between these without confusing or disorient the player. Bellow I will go through the process of creating these cameras and the 6 different transitions I incorporated, as well as how I structured these cameras code to make the different behaviours as separated as possible.

Project Details

Production Time: 20 days , halftime
Platform: Unity

Asset Packs Used:
Jammo Character | Mix and Jam (removed Cinemachine camera controllers and modified movement script),
LowPoly Environment Pack

 Cameras

First-Person Camera


Rotation

Probably the simplest of the cameras. The camera is tied to the players head and rotates up and down while input in the x rotation is sent to the player model.

 
FirstPersonCamera.png

Editor Features

  • When entering the first-person camera you can specify meshes that should turn of, for exampel like head meshes that have a chance of being visible from the inside.

  • How much you want the camera to be able to rotate in the “pitch“ axis.

  • The sensitivity of the rotation input

Third-Person Camera


Rigs

The camera is restricted by a number of rigs specified in the editor and to know the position of the camera you first have to figure out which rigs the camera is between currently. After you have found which 2 rigs you are going to use, you rotate in the XZ-plane which gives us a direction from the rigs’ center to use with their radius to calculate 2 positions on the edges. With the 2 positions we have calculated we can now make use of a Lerp function to find our Y position in the world.

Movement

Movement of the player uses the cameras rotation to calculate the direction the inputs correspond to.

 

Rig positioning

Editor Features

  • You can specify how many Rigs you wanna use to make the movement more sphere/eliptic than it already is (or any other shape based on circles)

  • Rotation sensitivity can be changed but since XZ -plane position is calculated through rotation and Y position on a lerp percentage the speeds arent unifrom and are going to need vastly different values.

 
 

Rail Camera


Rail.gif
RailCamera.gif

Rail

The rail camera follows a rail created by nodes where it finds the closest node, its closest neighbour to the player and lerps between these points. The lerping value is calculated by using the dot product of the vector from the closest node to the player and the closest node to the second node.

 

Lerping value calculation

Movement

Movement works the same as with the “Third-person camera” and uses the camera rotation to change the direction the player inputs create, but this time the player only have indirect input to the camera thorugh movement which made it easier when creating the transition to rail camera later on.

 
 

Transition Camera


The “Transition camera“ has 4 different behaviours and which is chosen is based on the current camera style and what style we are changing to.
Some camera styles transition better to others, so the set order of transitions I have come up with are these:

  • First to Third & Third to First

  • Third to Rail & Rail to Third

CameraTransitionEditor.png

These were chosen so the camera positioning could change in increments instead of traveling far distances and minimize the time spent in a transition.

The decision to make the transition its on camera is to confide the different behaviours to separate objects which makes it easier to work with and make it easy to add on to. Making its own camera also makes it less confusing when naming variables since transitions have its own acceleration and speed just like the normal cameras have their own rotation speeds corresponding values.

 
  • First To Third

“First to third” will always put the “Third-person camera“ directly behind the player so the transition is more predictable. The “Transition camera” slerps into the right rotation and uses the players movement speed aswell as its own to get into the correct position, this is done to prevent the player from being able to run away from the camera if it would be slower.

 

First to third update

 
  • Third to First

 

Third to first update

“Third to first” doesnt do a whole lot, most of the work is done in the “Camera View Manager” since transitioning into first person needs to change how the movement system handles input.

 
  • Third To Rail

One of the longer transitions which means that rotation can really screw you over, if we start rotating towards the rail cameras rotation without moving the proper distance the camera might not even point towards the player anymore. So instead of always slerping towards the end rotation we ask our “To camera“ to return a rotation which in this case is a “Look at” rotation.

Choosing a side

A problem that occurred early in development was that the transition moved over the player.
This was very disorienting and made it impossible to predict what your inputs would do, so I made a small function to figure out which side of the player the transition should happen on and then make it move away from the player if it gets closer than allowed.

choosing a side

keep away

 
  • Rail To Third

Rotating the “Third-peron camera” to always be in inbetween the player and the “Rail camera” makes this transition an easy one and very smooth aswell. Usually slerping towards a “Look at” rotation in this case would be more correct but since the repositioning of the “Third-preson camera“ results in barely any rotation at all I didnt prioritize changing it.

 

Rail to third transition update

 Camera View Manager

The place where everything connects.

The Update

This is where the active camera gets it input and where the transitions between cameras are triggered. The camera styles’ enums are ordered so the neighbour is always a camera style they are able to transition to, which makes it easier to iterate through with inputs. If a change camera style input is sent the manager will change the camera style and movement style to transition and then keep on checking each frame for “true“ to be returned from the “Transition camera”.

Transitions Update/Return Method

This is were the “Transition camera” updates and its called by the “Camera view manager”. It will keep returning false, until the transition has reached its correct rotation and position.

Movement Style Change

This is were the characters movement is changed and were the camera it should be getting its directions from is set. Some transitions also changes the players movement here to make it simpler for the camera to transfer.

Camera Style Change

This does exactly what it says, it changes the current camera style to a new one. The old camera is disabled and the new current one is enabled.