How can I program a hazard/trap to instantly kill my character and play the death animation?

I have the start to a decent damage system where I can press a key on the keyboard and it will deal 1/10 damage, knock back my character, and make him flash a few times to alert you that he was hit. Now I want to set up a trap or a hazard that, upon impact, will instantly kill the player character and initiate the proper animation accordingly. I watched a couple tutorials on how to do it but neither method worked for me. Any help would be greatly appreciated. Thanks in advance!

GR1M

P.S. I’m working in Paper 2D so keep that in mind. There are some key differences between using the two different setups.

Hey G21M-

Depending on how your death animation is setup, you can set a trigger volume where you want the trap to be and when the player enters the volume you can set health to 0, play the death animation and then destroy the character.

Cheers

Hey, , I have it set up as a single-sprite flipbook that’s triggered when the game recognized the character as “IsHit” and as “HealthCurrent” being equal to or less than 0. I’ve managed to get the health in the Progress bar to deplete after hitting the trap, but I I’ve had no luck in getting the death animation to activate. Any ideas? Thanks for the response, by the way.

GR1M

I’m not sure exactly what you mean by IsHit. If this is referring to a Boolean value, you should be able to set it to true when the overlap occurs. If you are referring to an actual hit event then there is a slight be more work involved. Assuming it is a hit event, one solution would be to create a ray cast when the overlap occurs. If you set the start of the ray cast as the center of the trigger volume and the end as the center of the character, that should give you a hit event.

Hey, , thanks so much for your help. I ended up figuring a way out before I had a chance to check out your response, but I appreciate the assistance you provided.

GR1M

I solved this one, too, and I’ll post my Blueprint Graph in case it’s helpful to anyone else attempting to do this using the Paper 2D plugin on UE4. Here’s what my graph looks like:

  1. The Initial Hit, Removal of Health, and Switching of Sprites

It all starts when my player character overlaps the collision on the Spike. When this happens, I have a Set Is Hit (Boolean) that gets checked, which executes Disabling of Input to the Player Controller (this keeps the player from being able to slide the dead character around the screen). Then, we Get the Current Health of our character, we Subtract 1 (100% in this case) of the health, and have it Set that value (which will be equal to or less than zero) as the new Health Current. This is what takes away the health from the health bar. Then, we execute a Set Flipbook and set the flipbook to the Death animation (in my case, a single sprite). I hope this helps anyone else having an issue with this situation on their blueprint graph!

GR1M

how did you do the knock back system