Crushing the player?

How can I set up the game so that the player (and other actors) can respond to being crushed?

I had a sequence where I tested this by putting my player underneath a platform that was moving up and down. As it pressed down into my player, it just held him in place for a while, and then spat him out the side.

I’d like to set it up so that my player instantly dies. Although I could conceive that maybe I would want it to inflict damage, but either way, I have no idea how to do this. Where could I even find that function int he code? What is being checked?

Well, you could do something like: put two thin collider triggers on opposite sides of the player, and if they’re both colliding with something at the same time, the player is assumed to be crushed.

However, you need to be careful what you ask for; instituting a general rule that the player dies if they are ever squeezed implies that they can be crushed to death by two feathers that bump into them from opposite directions at the same time. (Or, say, a wall and an enemy that’s chasing them.)

In most games, you probably only want a few specific objects that are designed to crush the player to actually be able to crush them, in which case there may be a better approach. For example, if you’ve got a Mario-style Thwomp that falls on the player to try to crush them, you’re probably better off making a rule that the player dies if they ever touch the bottom edge of the Thwomp than trying to implement a general “crushing” mechanic.

I’m thinking about responding to the environment. If the player gets caught between moving platforms, or if I have a stage with a moving fixed camera and they get caught behind a wall and the camera moves on.

(In that last example you might think to put a collider that kills the player off the edge of the screen, but I’d rather have a collider blocking them from jumping off the screen, because it would be pretty lame if they died because they walked too far forward.)

It might be nice if I could set it up with a different effect for different moving platforms; I might want one at some point that isn’t lethal.