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. 

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!

Product Version: Not Selected
more ▼

asked Oct 01 '14 at 11:17 AM in C++ Programming

avatar image

6.8k 332 184 467

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

1 answer: sort voted first

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.

more ▼

answered Oct 02 '14 at 06:42 PM

avatar image

9.6k 319 205 449

avatar image eXi Oct 02 '14 at 07:39 PM

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.

avatar image ScottSpadea Oct 02 '14 at 08:12 PM


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.

avatar image eXi Oct 02 '14 at 09:44 PM

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

(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