How can I crush players?

If I have a platform that lowers to the ground and the player gets under it I should probably have them die rather than make the game go screwy.

So how would I even begin?

Off the top of my head it seems like a good solution would be to do a raycast below the platform, when it gets to be a certain distance from the ground have a “kill box” trigger enable under the platform.

But this seems like it may present issues.

Is there a better way?

Good question! Kinda revolves around “how squished must you be before you die?”

If the underside of the platform is insta-kill, you could just check if the player is on the ground and the underside touches their head.

If instead you want it to require “squishing” them a bit before death happens, giving them a chance to wriggle free, you might need also:

  • a notion of how far you can be squished
  • a way to squish you (vertical scaling is the easiest obviously)
  • a way to detect you exceeded the maximum squishage
  • perhaps an impaired movement when your head is being pressed down, eg, you can’t jump, you have to walk slowly when partially squished, etc.

You could also put an “auto crouch” trigger on the player’s head so they duck first, then if it touches their head and they are still crouched, gouts of shiny red blood replaces the player as they flatten like a blood sausage under a large anvil.

EDIT: and for extra effort, once they are doomed, you could disable player input and have the platform slow down as it mashes them into a fine paste, coupled with interesting audio of things that a player might sound like when crushed under such platform.

1 Like

That’s pretty much how I do it. Except I don’t even bother with the raycast. I just bake the damage trigger into an animation or playable timeline. You could also script it so that the crusher activates the trigger when it reaches some percentage of an extension length that is exposed to the level designer via the inspector. They all work. Game dev is nothing but smoke and mirrors. Reality needn’t apply.

As for how the player reacts, that entirely depends on the feel you are going for and maybe the speed of the crusher. A simple method is to simply kill the player when the trigger activates. A more complex system might involve several different triggers, some of the earlier ones might change the state of anything caught below so that they use different animations and movements (think of a Mario game where he might slow down and start to display a squashed shape before the end actually comes).

EDIT: Kurt basically ninja’ed me with more-or-less the exact same response lol

1 Like