Geek Culture
Published in

Geek Culture

Dead Zones — Dying by Falling

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.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Daniele Quero, PhD

Daniele Quero, PhD

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams