# Death fall

 0 Im a designer student and I am making a game which involves a player that dies when he falls from more than 10 meters. I have a lot of platform in my map from different height. I want to know how can I make a script that recognizes that my player dies when he falls more than 10 meters. How can i make a counter that calculates my fall every frame, every time my player fall?Thank you more ▼ asked Feb 17 '12 at 02:17 AM Toy 35 ● 15 ● 29 ● 35 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

1 answer: sort voted first
 0 Something like this should work, I believe: ``````if(!player.isGrounded) { //calculate the distance between our current height and the height we were in the last frame lastYTravelDistance = player.position.y - lastYPosition; //if the difference is negative, it means we're descending fallHeight += lastYTravelDistance < 0 ? lastYTravelDistance : 0; } else { //we check to see if we passed the allowed falling distance and kill the player if necessary if(fallHeight >= -deathHeight) KillPlayer(); //reset fall height since we landed (doesn't matter if we're dead or alive) fallHeight = 0; } //cache our current Y position for comparison in the next frame lastYPosition = player.position.y; `````` more ▼ answered Feb 17 '12 at 09:09 AM asafsitner 2.4k ● 2 ● 8 ● 19 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Topics:

x172
x100
x40
x3

asked: Feb 17 '12 at 02:17 AM

Seen: 415 times

Last Updated: Feb 17 '12 at 09:09 AM