“Resident Evil Unity”

Well hello!

This is a short post explaining how the “resident evil camera setup” in Unity was made. In case you don’t know what I talk about, I’m talking about this:

Before I go any further, I have to say the entire setup (point and click character + cameras) would be a hell a lot easier in UDK.

I wanted to make a point-and-click style game in Unity, which means I didn’t want to use WASD controls, nor thumbsticks or anything like that. This is mostly due to the fact I wanted the game type to be accessible by pretty much anyone who could use a mouse (including whoever’s mother, that’s right).

The entire system is made up of 2 different “parts” so to speak. First, the point-and-click navigation system. I am leaving that one out because you can easily find a code for that anywhere on the internet.

The second one is the actual camera system. This is very dependent on your level layout because you need to know where the cameras will be located, and how far they can see. Basically what you do is set up a series of trigger volumes (or solids, whatever you wanna call them) that will trigger the camera change when they are touched. The triggers will then deactivate one camera and activate the next one, and so on.

This means you need to have A LOT of trigger volumes and cameras. This would be no different in Unity or UDK, though.

The camera switching is done using 2 different scripts. The first one is attached to the player character, and is used to let it know what camera it should be using. The second one is attached to the triggers, and is used to activate the camera you want to use, while deactivating the camera you were previously using (in Unity you can’t do camera switching without deactivating the “other” camera).

The first script is this one (using Javascript):

#pragma strict
var currentCam : Camera;

function Start()
  // Enable the first camera   
  currentCam = Camera.allCameras[0];
  // disable all other cameras   
  for ( var i:int = 1; i < Camera.allCameras.Length; i ++ )
          Camera.allCameras[i].enabled = false;   

Every time you declare a variable, that creates a slot in your UI where you can attach an object. In this case we created the “current cam” variable, so in Unity you attach the first camera to this slot (meaning the camera that should be used right when you start the level).


The second script is attached to the trigger volume:

#pragma strict

//var thePlayerScript : SelectCamera;
var CamEnable : Camera;
var CamDisable : Camera;

public var objects : System.Collections.Generic.List.<GameObject>;

/*function Awake () {
    objects = new System.Collections.Generic.List.<GameObject> ();
    enabled = false;

function OnTriggerEnter (other : Collider) {
    /*if (other.isTrigger)
    var wasEmpty : boolean = (objects.Count == 0);
    objects.Add (other.gameObject);
    if (wasEmpty) {
        enterSignals.SendSignals (this);
        enabled = true;
      // disable current camera   
  //thePlayerScript.currentCam.enabled = false;
  // enable this camera
  CamEnable.enabled = true;
  CamDisable.enabled = false;
  // assign this camera as the current camera
  //thePlayerScript.currentCam = myCamera;
  Debug.Log( transform.parent.gameObject.name + " Triggered by " + other.gameObject.name );
  Debug.Log ("Hello");

function OnTriggerExit (other : Collider) {
  CamEnable.enabled = false;
  CamDisable.enabled = true;

Just like before, you will get the “cam enable” and “cam disable” slots in Unity. All you need to do is attach the camera that will be enabled when players enter this volume. The camera that should be disabled is the one from the previous volume.

There could be issues when you are going “backwards,” or as you add more cameras. You can also try checking out what happens if you leave the “cam disable” field empty and rely that the “thePlayerScript.currentCam.enabled = false” line will do the trick (haven’t tried it myself). After all, the “current cam” is always on memory, and the only thing you need is to let Unity know what the new camera is going to be.


~ by nemirc on June 30, 2013.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: