Download

C++ Melee Combat (Couch Knights style?)

Hi there,

Ive been trying to design melee combat for my game and have hit a huge bottleneck when it comes to actual melee animations (one handed weapons such as swords). With the advent of 4.5 and animation retargeting, i thought using the swings from couch knights would be ideal!

I took a look at the project and found that the melee was actually very satisfying and want to replicate it. My game is mainly built on cpp with very little blueprint on top. I can think of a few methods of making a melee combo system - but i would love to know how to replicate Couch Knights. My problem comes in extracting meaning from their blueprints (i dont really understand blueprint flow as i am not experienced with them as i am cpp) my original thought being that perhaps the moving forward occurred as root motion on the animation, but it does not seem to be the case.

I suppose my main questions are:

  1. Best method of moving a character forward per swing of the weapon? (Couch knights feels very good in this regard) is there more to it than adding velocity to the character capsule?

  2. Best method of comboing animations? (One swing leads into another etc, again, like couch knights). I understand aanim montages may be the way to go, but any resources (better yet, in cpp!) would be greatly appreciated.

Thanks a lot, any and all help would be very appreciated!

  1. There is a UE4 tutorial video about making a 3rd person punching motion, including different punches, and so on. Take a look at it, its very detailed =)

Good luck mate, I’ll be working on something similar in some time.

Sounds great. Do you happen to have a link?

It’s a little frustrating how all of Couch Knights is in blueprints, haha. I’d have gotten to grips with it quicker if it were C++. The solution might be to study it for several hours, but it seems like a bit of an unintuitive web - I was kinda hoping somebody had done something similar in borrowing from the Couch Knights example.

Thanks a lot for the suggestion, I will have a look

Sorry mate but I don’t really have it… I know its in the 3rd person BP tutorials and has to do with root motion, its probably the title.

As for couch knights, yeah same here, I hate BPs, they are so unorganized its hideous, I’m always looking for C++ versions of this and never find 'em. Anyway, what they do is basically check if the sword collision component hits something when its swinging, if it does, get the actor = damage, get the shield = block.

Yeah - I’ve actually done the damaging part of the equation (I’ve got a collider that overlaps and then calls a damage function I’ve written on the character) so that’s good. My problem is I’m relying on a terrible placeholder animation and it feels bad, so I’m trying to work out montages leading into further attacks in a combo and moving the character (probably with root motion, but again, Couch Knights doesn’t seem to do this and that feels great)

Thanks for the tips though, I will search for it!

There is a RPG kit somewhere on the forums, someone replied with some animations and a dummy sword, use them.
Out of curiosity, are you using per-bone accuracy or just overall mesh hitting?

Maybe this helps Animation Montage | Unreal Engine Documentation

A combination of C++ Logic and AnimMontages are the best, i did basic melee functionality for my ( on hold ) RPG Framework using just C++ and a Single Anim Montage that holds sections for my left to middle of screen swing and right to middle of screen swing

As long you handle your combos VERY close to the end of the animation ( So you get smoother blending ) its very straight forward

@alvarofer0020- Where did you get the sword and armor/mesh?

I’d go with collision, not with tracing, tracing will be terribly expensive on a large scale, and well, the accuracy can’t match a collision box’s

Meshes are from dead crusade, on hold game And on my experience i had in fact worst results with collision instead of tracing, i optimized my method as best as i could so i can have a large number of traces with no impact on memory

When did you make such tests? Was it recently? Perhaps you are right, to be honest I haven’t tested it, but I think they made several improvements in that field.
Out of curiosity, mind giving a overall idea on how your method works?

PS- Dead crusade is yours?

I did the test in UE4 4.3 , Not too long ago could be worse or better now in the latest engine iteration,

The overall idea of the tracing method is to have just 2 sockets on the weapon ( start, end ) use simple math to make up the locations for the rest of the traces along the weapon and use VLerp between the last frame trace location and the current frame trace location , So far its worked pretty well and i really havent seen or noticed any relevant perfomance hits

And no, Dead crusade belongs to Aesthetic Games

I am not familiar with Lerping, will take a look at it, thanks for the tip!

Asked about Dead Crusade exactly because of that, as I’m not grasping how you could have access to their meshes =) but thanks for the tip

I’ve managed to get a montage to work fairly well - it just chains attacks quite simply. The problem I’m having is designing a decent solution for moving the character forward when attacking: is root motion best, or another method? As stated earlier, Couch Knights doesn’t appear to use root motion and that works quite nicely. I don’t think the “LaunchCharacter” function on character is ideal, as it gets interrupted by friction.

Any ideas?

As this is far from my field of expertise, I can only offer the following: Root motion has been broken till recently (ref. the Advanced Anim Pack thread in the marketplace forum). This might be the reason why couch knights aren’t using these, in stead of the reason being any tangible pros or cons one way or the other.
My knowledge on the matter stops with this little bit of information though.

Still, I am making a similar system, so an answer to both of OPs questions would be appreciated, here as well.
To summarize these questions:

  1. What is the least costly (and by what degree) way of doing the (hit)physics of a sword swing: Trace(s) or collision?
  2. Root motion; to use, or not to use? I am going to delve into animations soon enough, and I would love some pros and cons. Realism > performance on this one (within the limits of reason, of course).
    This is actually a very important question these days (to me, at least), as it might be the deciding factor when deciding to go for the incredible movement set, just released in the marketplace, or not

Apologies to bump, but I don’t suppose a quick response from Epic (or whoever worked on Couch Knights or a similar project) would be able to give a pointer towards a best practice for this?

If not, I will try and do some performance testing and test how several methods “feel” and try and report to the community, but I’d save a hell of a lot of time with some pointers

I’d appreciate it if you did Mesothere, especially focusing on overlap/hit components on the weapons and see how accurate and reliable they are, vs a tracing method, seeing which is more reliable/accurate, and well, cheap.

I would really appreciate a response here. I have combed over couch knights once more but blueprints are so archaic that I literally cannot determine where the attack animation is even getting played, despite the search function. A bool disappears into an interface to which there appears to be no method of finding the eventual implementation, and it’s extremely frustrating.

I’ve tried making my own solution in the meantime based on root motion and it is actually quite decent, but it lacks reasonable blending, currently.

Mesothere a response in terms of what?

If you’re talking about the collision vs tracing, I’ve spoken with a few industry developers and they all claim to have worked with collision in UE4 and UE3 and prefer it, they say its dead accurate and cheap

I was getting a bit irate over the blueprints and the comment wasn’t very informative :stuck_out_tongue:

I’ve gotten a system running with motion and collision detection (not using tracing but collision volumes which I turn on when swinging and only interact with certain physics groups. I had 100 actors continually hitting one another with no noticeably performance loss. I’ll do some proper profiling later).

I’m actually going to attempt to utterly refactor all of my animation code into C++, because the blueprint will become entirely unmaintainable after some time. It is already greatly bloated. At least this way 99% of my game will be C++ and therefore easier for me to manage.