Hit-reaction based on attacks that hit the same area?

I’ve recently been trying to create a game heavily inspired by Punch-Out!! for the Wii and have been making some decent progress the past few weeks. But now I’ve hit another potential major roadblock.

I have animations for both right and left attacks towards the body and can set it up so that an anim montage plays when the opponent is hit there. The problem is that I can’t figure out how to use both of them depending on whether the opponent was hit by a left punch or right punch.

Basically, what I want is for the damage animation to play that corresponds with what attack the opponent was hit by.

Any and all help would be immensely appreciated!

you could create separate collision boxes and GetHitComponent, or you can use a trace and calculate the direction from the center.

I see!

Do you mind explaining how I could go about doing that?

i’d need to know how you’ve set everything up.

but to get you started yo could add 4 box collisions over you mesh, head, body, left, right. the when something collides with a box, say a linetrace for testing, the box can notify which anim to play.

Okay then.

What do you want me to show you?

the question is more how do you want to do it?

are you using anim montages with animnotifys to hit using collision boxes on the fists for example?

i’d say start out and if you get stuck show me what you have

Yeah, I was using sphere traces on the hand bones and using anim notifys in the anim montages

If I do have to use line trace in order to do it then I’ll have to look to how to do that since I haven’t used it before

Are these projectile attacks? you can make an interface, when the projectile hits a target make it send a message through the interface to the actor that it hit with a value of some kind for identifying itself (just name or an int or something), then upon receiving that message you make the character blueprint play the corresponding damage animation depending on the given value (use a switch statement).

If it’s not a projectile, you can still use the same approach, whatever actor makes the attack needs to send the message of what kind of attack it was to the attacked actor is all.

Oh okay! That’s sounds very much like what I’m trying to get!

Also, how do I do all of that? (Sorry if this stuff seems obvious how to do. Not too experienced in Ue4 quite yet.)

look up tutorials on how to use unreal blueprint interfaces.

Okay so I watched a tutorial on Blueprint Interfaces. But I’m still not too sure on how I would go about doing this.

Do I add the interface so that when I press a button to punch it changes the number?
Honestly I’m still pretty confused.

These are physical attacks, also.

How do you determine which fist is used? How do you determine if the fist hit the target or not?

The fist that’s used depends on which button I press. I have it set up so that in when I press “a” the left hook anim montage is used and “s” is for the right hook anim montage. At the moment I have yet to make the other attacking animations.

I have anim notify states that use sphere trace with apply damage that go off during a certain of the animation and have a print string set up to show me that the punch dealt damage if the sphere trace overlaps the opponent’s collisions.

Ok, so here’s what I’d do.

  1. Create an interface called “IF_Hit” and implement it in the player and npc bp.
  2. In “IF_Hit”, create a function called something like “Hit_Landed” and make it accept an integer as input.
  3. Create an integer in the player bp named “Fist” or something to that effect, default it to 0.
  4. When a is pressed “Fist” is set to 0, when s is pressed, “Fist” is set to 1.
  5. If a hit lands, get the actor you hit from the sphere trace, and send a message (you may need to untick context sensitivity in the node selector for the message node to show up) over “IF_Hit” to that actor (presumably the npc blueprint) with the value of “Fist” plugged into it’s integer input.
  6. In the NPC blueprint, on interface event ‘Hit_Landed’, play an anim montage depending on which integer was passed through and add any other code you want the npc to apply to itself after.

It’ll also make it easy to add more reactionary animations later if you add more attack animations or weapons.

Alright, I believe I have everything set up properly, except for step 5

I’m not sure how to fix this. Or do I have to make an anim notify state for every punching animation?

Aside from this everything works!

1 Like

Never mind, I figured it out!

Just had to create a variable in the anim notify states

1 Like

False alarm! It doesn’t work as I thought it would. Now it just plays the same damage animation regardless of the integer

You can use the Phys Asset collisions for this. You can also assign each one a Physical Material (PM_Head, PM_Arm, PM_Leg, PM Torso etc). Hit → Bone Name is helpful too.

1 Like

Physical Material is a good idea, i dont like bone name because you have to account for all the parts, upper, lower, left fingers haha etc

I use it for projectile hit detection. I also use the bone name in a data table look up for additional penalties.