Melee Impact/Knockback Question

So, I’m working on a game where the majority of the fighting is done through melee combat. The thing is, the player is controlling a bear, and the attack animation doesn’t actually connect with the enemy AI.

The way I’m envisioning it working in theory is this:

So the player triggers the attack, which then results in a sweep in front of the player. If the enemy is caught in the sweep, some damage and directional velocity/knockback should be applied. On top of that, if the enemy dies as a result of the attack, it should also ragdoll.

What I’ve done right now is that I’ve attached a stretched cube (“plank”) to the paw of the bear, with a box collision that is enabled only when the attack is triggered.

plank

I can successfully use it to apply damage and “kill” the enemy and make it ragdoll by simulating physics on the mesh. However, the main issue I’m having is that I’m not entirely sure how to apply directional velocity to the enemy with this method.

I’m thinking line traces would be the way to go here, but my knowledge on line traces is very limited, so I don’t exactly know how I would go about that in this scenario.

Any suggestions are appreciated.

I THINK IT IS SOMETHING LIKE ADD IMPULSE FOR CHARACTER MOVEMENT (IM SURE THIS IS THE ONE FOR ACTORS)

ITS ADD PHYSICS LINEAR VELOCITY OR SOMETHING LIKE THAT FOR COMPONENTS

I’m aware of the Add Impulse and Set Physics Linear Velocity nodes.

The problem is, I don’t know how to properly apply a directional impulse or velocity using those nodes, depending on how/where the attack impacts the enemy.

The best I can do right now is to just add an impulse or velocity in a set direction, but then the enemy will always get pushed in that specific direction, no matter where the attack is coming from, if I understand it correctly.

Try applying the damage like this. Make sure to use the point damage event in the enemy’s blueprint. From there you can get the hit direction vector and use it with a launch character node if you use a character blueprint for your enemy. If it is not a character you can use add impulse.

Implement the “on take any damage” or point/radial damage events, and apply the impulse in that handler (inside the enemy actor)

First off, I want to say thank you to those of you that have commented and tried to help me figure this out so far! I’ve sort of figured out a way to do what I want, so hopefully this helps someone out there.

Basically, I’ve moved to using a plugin called DidItHit, which essentially functions as a sort of LineTraceByChannel node, as I understand it.

Also, I should’ve probably mentioned that I’m using a blueprint interface to send the attack “message” to the enemy when a hit is generated. I’m doing this because it gets quite messy with all the references if I want to use multiple different enemy types and “Cast to…” for every single one of them, and this way I can use a single message for every single enemy that needs to take damage.

Now, with DidItHit set up, what I’m currently doing is this:

In the Player Character blueprint, I’m taking the Attack Damage and the World Location of the Player Character (Capsule Component) and sending it to the enemy through the blueprint interface (Bear Attack).

Message Sent

Then, in the Enemy Character blueprint, I’m subtracting the World Location of the Enemy Character (Capsule Component) with the World Location of the Player Character (Impact Point).

Message Receieved

Then I’m multiplying the vector by 2 and using a Launch Character node to knock the character back if it’s simply taking damage, without dying. (In the image, I have XYOverride and ZOverride checked, but they didn’t seem to make any noticable difference in this case, checked or unchecked).

Launch

If the Enemy Character “dies”, I’m using a Simulate Physics node to ragdoll the mesh, as well as multiplying the same vector as above, by 30 this time, and using a Apply Impulse node, with “Vel Change” checked, to push the ragdoll away from the player.

Ragdoll

And this is what it looks like in practice:

It’s roughly what I wanted to achieve, but I think it could be improved by adding a tiny bit of randomness to the direction that the enemy is pushed. If anyone knows how to make that happen, any suggestions are greatly appreciated!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.