Dead Zones — Dying by Falling

Daniele Quero, PhD
Oct 22 · 2 min read

Objective: make the player die and respawn after falling of a platform

How to make the player die by falling?

Well, the solution to the problem lies beneath the solution to another one: how do I detect a falling off a platform?

We could check for y-position being lower than a threshold or we could use triggers. The first option would force us to put the check in an update method and will be hardly (but not impossibly) made modular: think of platforms having different position in x and y, some of them may be placed at very low y values, so death would occur when the player gets even lower values. This means that we may have to take into account different thresholds for different areas or, if you want, a threshold which is a (step) function of x coordinate.

On the other hand if we use colliders, triggers, and OnTriggerEnter() method in a script attached to them, we can place many instances of them wherever we need.

When putting such a dead zone into the scene, I suggest to give it also a fairly enough large z scale, bigger than the usual platform scale: one may never know, maybe in the future we could exploit more the 3rd dimension of the 2.5D platform and create obstacles that push the player off the platform along the z axis. Better safe than sorry.

The script itself is really simple.

The Respawn() method in PlayerMovement class will simply put the player in a given position, after checking if it has enough lives. AddLife() method adds -1 to the life count and updates the UI.