Death Scene (zooms into Enemy's face)?

Hello! I have made a horror game and my death scene has always been when the Player’s HP goes to 0, the script loads a new scene, which is the death scene.

It now looks rather boring to me and reviewers are saying the same, so I would like to change it. I would like to have something a LOT similiar to the death scene in this game http://www.youtube.com/watch?v=0usffadlDvM (at 1:28).

I have never really understand how people have done this before with so many other horror games (such as SCP, Slender, Vanish, etc.) with an animation stopping the Player from moving and having the camera have the death animation.

I am using this script as a model:

var isNotDead:boolean=true;
    var showGameOverScreenLboolean=false;
    function Update(){
    if(isNotDead){
    // other things that you don't want the player to do while dead here
    if(health<=0){
    isNotDead=false;
    KillPlayer();
    }
    }
    }
 
    function KillPlayer(){
    GetComponent(CharacterController).enabled=false; //makes the player unable to move
    //Other things here
    Screen.showCursor=true;
    Screen.lockCursor=false;
    showGameOverScreen=true;
    }
 
    function OnGUI(){
    if(showGameOverScreen){
    //GUI code with whatever you want to have at the death screen.
    }
    }

This stops my player from moving while the death animation occurs, but I’m not sure on HOW to do this animation… I just need to tweak the script for Android and I already have death on collision if anyone tries to confront the Enemy or it gets too close (then I want to be able to add in the animation for the collision script).

Any help will be extremely appreciated! :slight_smile:

I would say you have to have have an animation attached to the main camera that turns to the enemy that killed you and zoom in on him/her. Then when the player dies you would call it… But I would make a var that is attached to the anim… Then when the player dies that var is called, ie the anim. I will mess around with this and post the code if it works. :slight_smile:

The animation itself can’t be done in OnGUI - you must move the camera by code between two points and, once the movement has ended, enable the GameOver message. Since you have only one enemy, a simple solution is to create two empty game objects and child them to it; adjust their positions, one farther (“Start”) and other closer (“End”) to the enemy. Modify your script like below and drag these two objects from Hierarchy to the fields start and end in the Editor:

var start: Transform; // drag here the start empty object
var end: Transform; // drag here the end empty object
var duration: float = 1.6; // set duration of movement
var isNotDead:boolean=true;
var showGameOverScreenLboolean=false;

function Update(){
  if(isNotDead){
    // other things that you don't want the player to do while dead here
    if(health<=0){
      isNotDead = false;
      KillPlayer();
    }
  }
}

function DeathCamera(){
  var cam: Transform = Camera.main.transform; // get camera transform
  cam.parent = null; // detach it from the player
  cam.position = start.position; // place the camera at the start position
  cam.LookAt(end.position); // make it look towards the end position
  var t: float = 0;
  while (t < 1){
    t += Time.deltaTime/duration;
    // move the camera towards the end position each frame
    cam.position = Vector3.Lerp(start.position, end.position, t);
    yield; // let Unity do other jobs til next frame
  }
  // movement ended - enable game over screen
  showGameOverScreen = true; // enable "Game Over" message in OnGUI
}

function KillPlayer(){
  DeathCamera(); // start DeathCamera coroutine
  // not sure if the line below effectively stops the player...
  GetComponent(CharacterController).enabled=false; //makes the player unable to move
  //Other things here - showGameOverScreen is activated by DeathCamera
  Screen.showCursor=true;
  Screen.lockCursor=false;
}

function OnGUI(){
  if(showGameOverScreen){
    //GUI code with whatever you want to have at the death screen.
  }
}