# Scripting a Death Fall

**URL:** <https://discussions.unity.com/t/scripting-a-death-fall/37348>\
**Category:** Questions & Answers\
**Created:** [February 28, 2012, 3:51am UTC](https://discussions.unity.com/t/scripting-a-death-fall/37348 "2012-02-28T03:51:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toy](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@Toy](https://discussions.unity.com/u/Toy)\
**Post date:** [February 28, 2012, 3:51am UTC](https://discussions.unity.com/t/scripting-a-death-fall/37348/1 "2012-02-28T03:51:40Z")

</div>

Hi there, Im stuck with a problem since at least 2 weeks.  
I searched for lot of info and forums and stuff but nothing.

I want my character dying every time I fall from 8 meter or more.

Is there a simple way to script this . My environement is huge and lot of denivelation. Can I script something without having a huge empty plane to detect the collision ?

What im trying to script with no success is to register the last time I was on the ground ( Y position ), register the next position grounded ( Y position ) and make the difference, if the difference is 8 or more kill my avatar.

Please help me

---

<div class="post-metadata">

**Author:** ![aldonaletto](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/aldonaletto/32/44226_2.png) [@aldonaletto](https://discussions.unity.com/u/aldonaletto)\
**Post date:** [February 28, 2012, 10:43am UTC](https://discussions.unity.com/t/scripting-a-death-fall/37348/2 "2012-02-28T10:43:05Z")

</div>

I would do exactly the same thing: measure the fall height from the last grounded position to the new ground location, and apply damage or kill the player, depending on the height. If you’re character is a CharacterController, you can do the following:

```
var falling: boolean = false; // tells when the player is falling
private var lastY: float; // last grounded height
private var character: CharacterController;

function Start(){
  character = GetComponent(CharacterController);
  lastY = transform.position.y;
}

function Update(){
  if (character.isGrounded == false){ // 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...
      if (hFall > 8){ // then check the damage/death
        // player is dead
      }
    }
    lastY = transform.position.y; // update lastY when character grounded
  }
}
```
