x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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.

Product Version: UE 4.10
Tags:
more ▼

asked Jan 18 '16 at 02:34 PM in Blueprint Scripting

avatar image

Charlie shepherd
1 3 5 6

avatar image Matthew J Jan 18 '16 at 09:23 PM

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.

avatar image Charlie shepherd Jan 21 '16 at 12:46 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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!

more ▼

answered Jan 21 '16 at 01:45 PM

avatar image Charlie shepherd Jan 21 '16 at 04:41 PM

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

avatar image Matthew J Jan 21 '16 at 07:16 PM

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.

avatar image Charlie shepherd Jan 25 '16 at 09:59 AM

(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.

avatar image Charlie shepherd Jan 25 '16 at 11:57 AM

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

avatar image Matthew J Jan 25 '16 at 01:48 PM

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.

avatar image Charlie shepherd Jan 25 '16 at 03:49 PM

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

avatar image Matthew J Jan 25 '16 at 04:31 PM

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.

avatar image Charlie shepherd Jan 28 '16 at 12:46 PM

OK thank you honestly for all your help

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question