x


Death fall

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 gravatar image

Toy
35 15 29 35

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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 gravatar image

asafsitner
2.4k 2 8 19

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

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