• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by hanaharu7 · Feb 03, 2014 at 04:13 AM · camerajavascriptlookatdeathstay in place

Demons Souls Fall death Camera

Hello!

I'm trying to achieve a certain affect for my players death when falling into a pit. Similar to demons souls, I'm attempting to make the camera stop in place after the player falls a set distance. The camera would then watch the player as they fall and the screen fades to black.

Ive got a basic setup for the screen fade but I haven't a clue as to how I can approach what I'm going for.

 #pragma strict
 var falling: boolean = false; // tells when the player is falling
 private var lastY: float;     // last grounded height
 private var character: CharacterController;
 var duration = 5.0; // fade duration in seconds
 
 function Start(){
   character = GetComponent(CharacterController);
   lastY = transform.position.y;
 }
 
 function Update(){
   if (!character.isGrounded){ // if character not grounded...
     falling = true;        // assume it's falling
   } else {                   // if character grounded...
     if (falling){            // but was falling last update...
       var hFall = lastY - transform.position.y; // calculate the fall height...
       var timeinair = 0;
       var deathtimer = 10;
               timeinair += Time.deltaTime;
       if (timeinair >= deathtimer){        // then check the damage/death
  
            Die();   // player is dead
       }
     }
     lastY = transform.position.y; // update lastY when character grounded
   }
   }
   
 function Die(){
   // create a GUITexture:
   var fade: GameObject = new GameObject();
   fade.AddComponent(GUITexture);
   // and set it to the screen dimensions:
   fade.guiTexture.pixelInset = Rect(0, 0, Screen.width, Screen.height);
   // set its texture to a black pixel:
   var tex = new Texture2D(1, 1);
   tex.SetPixel(0, 0, Color.black);
   tex.Apply();
   fade.guiTexture.texture = tex;
   // then fade it during duration seconds
   for (var alpha:float = 0.0; alpha < 1.0; ){
     alpha += Time.deltaTime / duration;
     fade.guiTexture.color.a = alpha;
     yield;
   }
   //reload the current level:
  Application.LoadLevel(0);
 }

I feel like I have to unparent the camera from the FPS, but im not sure.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Klarax · Feb 03, 2014 at 11:15 AM

Could you not, put a trigger collision where you want the camera to stop, and then use clamp to stop the camera moving any further?

Below will stop the gameObject from moving between -7 and +7 in the axis. Maybe modify this ?

horizontal = Input.GetAxis("Horizontal") speed Time.deltaTime; vertical = Input.GetAxis("Vertical") speed Time.deltaTime;

 var pos : Vector3 = transform.position;
 pos.x = Mathf.Clamp(pos.x + horizontal, -7, 7);
 pos.y = Mathf.Clamp(pos.y + vertical, -7, 7);
 transform.position = pos;
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hanaharu7 · Feb 03, 2014 at 05:40 PM 0
Share

I don't believe so with the way I have my world set up; Since both it and my character can move. I'll give it a shot though

avatar image hanaharu7 · Feb 03, 2014 at 06:27 PM 0
Share

Had to mess with it a bit, but it worked! Thanks alot!!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How Can I Stop Rotation From This Script? 0 Answers

Look at wont update? 2 Answers

Help have script know how many enemies are in the world 1 Answer

Disabled Camera After Animation Finishes 1 Answer

Need some help with portal rendering 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges