How do I make a 2D enemy deal damage to my characters health (character max health of 3) when they collide Meshes

How do I make a 2D enemy deal damage to my characters health (character max health of 3) when they collide Meshes, it’s a 2D platform for an endless runner character has a health bar with a maximum of three health and the enemy needs to do 1.0 damage.

Hello Charlie,

Depending on how the collision is set up between these two characters, the best way to do this would be with either OnActorHit or OnActorBeginOverlap. If the two actors will collide and block each other, then OnActorHit would be the best option. If they pass through each other, you’ll need to ensure that overlap events are enabled and use OnActorBeginOverlap.

Do you plan to destroy the enemy when they collide with the player or will they still exist? If they are going to be destroyed you should be able to just set the value when those functions are called and then destroy the actor. If not, it may be more complicated but I’ll need to know more about how that is intended to work to say more.

I will destroy the enemy actor and replace it with a got hit animation on the player actor.

You should be able to just use the “OnComponentHit” event for the Root Component in your Character blueprint. To add this, you’ll need to select the Root Component and then right-click in the Event Graph. Type “hit” and “Add On Component Hit” should appear. This event will be called any time the root component collides with something blocking. The Other Actor pin will refer to the other actor.

To ensure that the other actor is an enemy, you can use the Other Actor pin to create a “Cast To” node for your enemy’s blueprint class. From that, you can trigger the animation on your character, deduct the 1 health, and destroy the other actor.

Hope this helps!

Do I need a blueprint for my enemy character or do I just need the player character to have a blueprint

You shouldn’t need a blueprint for the enemy. If you’re not going to use a blueprint, it’ll depend on what type of Actor your enemy is. You’ll need to cast to whatever class that your enemy is to make sure that you’re not calling this logic on other things such as walls and floors.

(Thank you for helping so far by the way) How do I define that the difference between the enemy and the walls and floors because my character takes damage from the floor while jumping and hitting the invisible wall barriers so how do I define that the enemy is the only one meant to deal the damage to the player.

Found way to do last one but how Do I make the enemies sprite and mesh disappear and show the you got hit animation

From the output of the Cast To node, you should have that reference to the enemy still. You can use that to call Destroy Actor which will get rid of the enemy. If you wish to just make it disappear instead you can set its visibility.

As for the animation, you should be able to use the Play Animation node in the same line of execution as destroying the enemy or setting its visibility.

How do I play my getting hit animation for the player as a flip book animation when ever my health is depleted for any reason

Animations are not quite my expertise. I would suggest creating another question for this issue as it is starting to move away from the original question.

OK thank you honestly for all your help