Home  || Previous || Next

3D Camera Controls – Unity – James Workshop

Quaternion – mathematics of rotations (Wikipedia Article)


  •  Euyer angles (x,y,z)
  • Quaternions: constant variable, extension of complex numbers (real + imaginary*3 )
    • 3 Imaginary parts stand in for x,y,z
    • 4D arcideials spirals/ moving and not moving.

Unity – deals with the quaternions within the background.


Basic Camera Controls:

Create a 3D Project to a specific folder

Screen Shot 2015-10-19 at 10.14.17

Unity opened

Screen Shot 2015-10-19 at 10.15.38

Create world to work in, add a plane

Screen Shot 2015-10-19 at 10.17.46

Transform plane on y axis to -1, so that character sits above plane

Screen Shot 2015-10-19 at 10.18.47

Rename plane: world

Add cube, name: player

Screen Shot 2015-10-19 at 10.19.57

Select, Main Camera, this shows you what you will see in the game world

Screen Shot 2015-10-19 at 10.21.23

Create a script, c Sharp, name: Movement

Screen Shot 2015-10-19 at 10.22.53 Screen Shot 2015-10-19 at 10.23.06

Edit in Sublime Text

Screen Shot 2015-10-19 at 10.24.25

Create Tank Control movement (back/forth/rotate)

Add float movementSpeed, rotationSpeed.

Screen Shot 2015-10-19 at 10.27.07

In Update function use function GetAxis where Unity gets the horizontal number.

Multiply Horizontal by rotation speed by Time. (Gets faster as you hold it longer)

Screen Shot 2015-10-19 at 10.29.26

Rotate on y axis, rotate on x axis.

Only use these variables in this function as it is local

Screen Shot 2015-10-19 at 10.31.48

What we have written is in the Unity script space:

Screen Shot 2015-10-19 at 10.32.58

Add Script to player: Drag script onto player

(First add a drag coefficient to the end of the vert script) f means its a floating number:

Screen Shot 2015-10-19 at 10.34.57

Screen Shot 2015-10-19 at 10.35.39

Sort out spelling then play scene… it moves!:

Screen Shot 2015-10-19 at 10.38.02 Screen Shot 2015-10-19 at 10.38.15

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour {

public float movementSpeed = 10f;
public float rotationSpeed = 60f;

// Use this for initialization
void Start () {


// Update is called once per frame
void Update () {

float horiz = Input.GetAxis(“Horizontal”) * rotationSpeed * Time.deltaTime;
float vert = Input.GetAxis(“Vertical”) * movementSpeed * Time.deltaTime * 0.4f;


Start Camera Controls – The “Lucastarts” Camera Controls

  • Used like a CCTV camera where you can rotate the camera
  • Good for enclosed rooms, adventure games, see the entire scene in one go
  • Easiest camera to script

Create Script
Screen Shot 2015-10-19 at 10.43.47

Create GameObject player (where we created floats) Creating a stalker camera:

Assign player to game object – player

Screen Shot 2015-10-19 at 10.46.02

Use built in function of unity – look at (does the quatrains calulations)

Screen Shot 2015-10-19 at 10.47.06

Add script to camera, camera follows cube:

Screen Shot 2015-10-19 at 10.48.58Screen Shot 2015-10-19 at 10.50.15 Screen Shot 2015-10-19 at 10.50.23Used in wii games and PS2 games.

using UnityEngine;
using System.Collections;

public class LucasArts : MonoBehaviour {

public GameObject player;

// Use this for initialization
void Start () {


// Update is called once per frame
void LateUpdate () {

player = GameObject.Find(“Player”);


“Daiblo” Camera Controls

  • Used for dungeon crawlers
  • Allows you to scroll through the environment like 2D game.
  • Focused on player (always central) and surrounding.
  • 3rd Person Camera, to see more than 1st Person
  • Isometric, top down view is good – or birds eye perspective.

New script -Diablo

Screen Shot 2015-10-19 at 10.54.48

LATE UPDATE: (takes a little bit longer than the update – should be used for camera controls, allows players to finish moving to where they were going to, then the camera follows.)

Create variable GameObject and 3D vector – diff: which is the offset for camera.

diff is the difference between the transform position and the players position.

Vector3 updatedPosition = player.transform.position + diff; allows the camera to move above the player.

transform.position = updatedPosition; puts the camera in to the position.

Screen Shot 2015-10-19 at 11.00.52

Add to camera:

Screen Shot 2015-10-19 at 11.01.26

Move Camera to a Diable perspective.

Screen Shot 2015-10-19 at 11.03.12 Screen Shot 2015-10-19 at 11.03.25

Camera always follows player – we could go to full birds eye view:

Screen Shot 2015-10-19 at 11.06.12

using UnityEngine;
using System.Collections;

public class Diablo : MonoBehaviour {

public GameObject player;
Vector3 diff;

// Use this for initialization
void Start () {

player = GameObject.Find(“Player”);
diff = transform.position – player.transform.position;


// Update is called once per frame
void LateUpdate () {

Vector3 updatedPosition = player.transform.position + diff;
transform.position = updatedPosition;


“Resident Evil 4” – Over the shoulder position – Camera

  • Gears of war, Space maria also.
  • Over the shoulder camera
  • Use if a 1st person perspective doesn’t give enough environmental information
  • Used mainly for shooters.

Make new scriptScreen Shot 2015-10-19 at 11.15.28

Create game object and different holder for offset.

Add angle of rotation using euler angles of y

Screen Shot 2015-10-19 at 11.17.53

Add in a quaternions for rotations:

Quarternions, conversation mathematics for Euler, and only interested in rotation on y axis. Screen Shot 2015-10-19 at 11.19.52

Now multiply the rotation matrix by the difference.

Screen Shot 2015-10-19 at 11.22.09

Add Script to camera, now has over the shoulder feel:

Screen Shot 2015-10-19 at 11.25.30 Screen Shot 2015-10-19 at 11.25.10

using UnityEngine;
using System.Collections;

public class RE4 : MonoBehaviour {
public GameObject player;
Vector3 diff;

// Use this for initialization
void Start () {

player = GameObject.Find(“Player”);
diff = player.transform.position – transform.position;


// Update is called once per frame
void LateUpdate () {

float editAngle = player.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, editAngle, 0);
transform.position = player.transform.position – (rotation * diff);


Unity has a built in for 1st Person 

Download Character Asset (not Vehicles):
Screen Shot 2015-10-19 at 11.32.51


Lurping is a function which helps with camera transitions

  • Takes the vector lines and works on stops and starts.



  • Design single room
  • With single player
  • With single action/mechanic
  • Use appropriate camera control

What is the justification for design choices.

5 to 10 page document for choices, to go along with presentation.


Home  || Previous || Next