Resident Evil Cameras

Hello

I want to make a game like resident evil’s classic,
but I don’t know how to make a camera change to position
to another. If somebody managed to change and created a
game like resident evil, please explain.

Sorry for my bad english.
Thank you.

I wrote an answer for this ages ago, it never even got accepted (or voted, I accepted it myself, sigh).

So, from my answer on : Switching Several Cameras(HorrorGame) - Questions & Answers - Unity Discussions


So I have been thinking about this, and may have a flexible approach.

Each camera is a component or child of your trigger object. So tell the camera to enable when the trigger is entered. But then there is the problem of turning the old camera off. Just store a reference to the currently used camera, and when the trigger enables a new camera, then disable the stored one, then make sure to store a reference to the new current camera.

Here is some rough untested code to try and explain the theory. The idea then is no matter how many cameras there are, this should keep working (as long as the trigger volumes are not too close together). Adding or removing cameras and trigger volumes becomes fun, not a hassle with rewriting code =]

// – PLAYER SCRIPT –

#pragma strict

// FOR MULTIPLE CAMERAS
public 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*.enabled = false;*
  • }*
    }

// ----

// – TRIGGER SCRIPT –
#pragma strict

var thePlayerScript : PlayerScript;
var myCamera : Camera;

function Start()
{
// find myCamera (child or component of trigger object)
myCamera = transform.parent.FindChild( “Camera” ).GetComponent( Camera );

// find the Player, store reference to player script
// to use .enabled = false; when switching cameras
thePlayerScript = GameObject.FindWithTag( “Player” ).GetComponent( PlayerScript );
}

function OnTriggerEnter( other : Collider )
{
// disable current camera
thePlayerScript.currentCam.enabled = false;

// enable this camera
myCamera.enabled = true;

// assign this camera as the current camera
thePlayerScript.currentCam = myCamera;

Debug.Log( transform.parent.gameObject.name + " Triggered by " + other.gameObject.name );
}
Any feedback is most welcome =]
The theory works : http://www.alucardj.net16.net/unityanswers/ResEvilCameras.html

Put more than one camera in your scene. Then turn them on and off as necessary - perhaps with a script like the one at the bottom.

Using this script you would drag each of your cameras into the shots on the CameraController script, attached to your player.

Then you would create some triggers that would cause other shots to play out - each of these trigger components would have the CameraShot.js script attached. In the inspector on that script you would specify each of the shot numbers and the delay for each shot.

You could do this by having a Camera on the CameraShot script too - it depends how you like to thing about it.

#CameraController.js

 var shots[] : Camera;

 function SelectShot(shot : int)
 {
     for(var camera in shots)
     {
          camera.enabled = false;
     }
     shots[shot].enabled = true;
 }
 //Just an example of using a few shots
 function Start()
 {
       SelectShot(1);
       yield return WaitForSeconds(1);
       SelectShot(2);
       yield return WaitForSeconds(1);
       SelectShot(0);
 }

 //A good way of making a trigger show a shot for some time
 //use with the CameraShot.js on the same object as the trigger
 function OnTriggerEnter(other : Collider)
 {
      var shots = other.GetComponent(CameraShot);
      if(shots)
      {
           for(var shot : int in shots.shots)
           {
                 SelectShot(shot);
                 yield return WaitForSeconds(shot.shotDuration);
           }
      }
 }

#CameraShot.js

  var shots : int[];
  var shotDuration : float = 2;