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.
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.
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.
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.
Create an interface called “IF_Hit” and implement it in the player and npc bp.
In “IF_Hit”, create a function called something like “Hit_Landed” and make it accept an integer as input.
Create an integer in the player bp named “Fist” or something to that effect, default it to 0.
When a is pressed “Fist” is set to 0, when s is pressed, “Fist” is set to 1.
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.
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.
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.