What is the best way to achieve Zelda like Swordfighting?

Hey guys,

i’m wondering how to achieve a “good” SwordfightingSystem like the one in Zelda.

I’ve searched for Sword Meele Tutorials or Threads but only found answered questions.

I have 2 options on my mind

First using the Overlap Function of a trigger box that would be placed around the sword
and a bool that checks if we are attacking (so that we can’t harm someone in idle position).

Maybe a second parameter that tells what attack we used, because the longrange cut where Link
jumps deals more damage than a normal swordswing.

And the second option would be to do a raycast only a few units away from the sword and
track if we hit something (most likely when the sword runs through an enemy).

Is there another option and what of those two would be the best?

How is blocking done? If i hit someone, i would directly check if he is blocking with a bool inside the enemy class and react to it with less damage and a repell animation of my character or how would i do this?

Thanks for your help!

you could use an anim notify to call a function at the moment the damage is supposed to begin and end. use those begin and end functions to control a bool, and use that bool to decide whether to trace for damage. if the bool is true, trace between current position and last position of a socket every frame to get a line that follows the socket. if you do this from several places along the blade, you can see if the sword hits something.

using the data from the trace, you can cast to an enemyPawn and get access to any enemy data you want to check, like whether they are blocking.

when you set up a blocking animation in the animGraph of your enemy, you will have a blocking blend node with a variable that controls it. check the value of this variable to know if they are blocking.

how your character reacts to blocking should depend on a lot of factors that you need to design specifically for your game. in some games, you would have complicated item stat calculations that take into account the attacker’s weapon’s attack points, the victim’s armor’s defense points, and any extra modifiers your attackers and victims can wear.

you might have enemies wearing magic items that block all melee attacks or have your character wearing magic items that cause melee attacks to be unblockable. if both of these weapon attributes exist, you need a formula that resolves these issues. this formula can be as simple as a listing all attacks in order of precedence, and defining blocking as a type of attack. if your attack ranks higher than the enemie’s block, they get hit. the list of attacks can have several different blocks, varying in rank.

the way you want to rank your attacks and blocks depends on your game design, you might want special cases for random critical hits, or limit breaks, or charge attacks, but you might want special bosses that can still block those unblockable attacks, so a blockEverything attack should rank highest on the list, so it overrides any attack.

Hey, thanks for the long answer (:

So the notify calls are based on what? Haven’t worked with this so far.

Do i use the time of a the animation? For example when it’s played 6 seconds i use a notify call to change the bool to true and at 8 i use a notify call to change it back? That would be a nice way to set the time where the attack should deal damage.

And the trace: The trace would be as long as the sword moved within one tick.

The socket transform for one trace is easy to get, but how do i get “several other places along the blade”? Can i get the local position of the socket and add 3 units multiple times from the handle to the point of the sword? With a for loop or so?

Would’nt it be easier to use a local point at the handle and a local point at the point of the sword to draw one line through the whole sword as long as the boolean is true?

(: Thanks for your help so far.

tracing from hilt to tip is more likely to miss than tracing from last position to current position at several points. some fast attacks might only be a few frames long, and enemies might be thin, so it would be like the sword is teleporting past them and some hits wouldn’t register.

you could have 2 sockets on the sword and VLerp between their positions at increments that depend on how many traces you want. if you want 5 traces, you could add .25 to the alpha of the VLerp during each cycle of the loop.

(: Ok thank you. I will test this and if i run into problems i will comment again.

Until then, i will mark the question as resolved.