Anyway, in some platform games you need to make the player die if falling from high places.
Try to play this prototype:
You can play with ARROW keys, and perform double jumps.
If you fall down the left cliff, you will die (actually, you turn gray for couple of seconds – that’s how I show you would have died).
If you fall down the right cliff, you won’t die.
If you jump from the right cliff and fall down, you will die.
This happens because there’s a maximum falling height. If you’re falling for more than such height, you will die.
To make this kind of behavior, first we need some attributes:
is falling is a Boolean variable to determine whether the player is falling or not
falling start is the y coordinate in pixels of the player when it begins to fall
deadly height is the height, in pixels, of the deadly height. Also notice this attribute is not hidden so it can be set when the behavior is added to the player:
Then, this is the behavior:
As you can see it’s just a matter of checking if player’s y speed is greater than zero (the player is moving down, so it’s falling), and once it hits the ground again, calculating for how long it kept on falling.