Player knockback

I want my player character to get knocked back when an enemy hits me. I made a blueprint for this but I can only get knocked back in certain directions. I want to get knocked back in the opposite direction I got hit from. Here’s an image.

I got this blueprint from someone talking about this same thing but it seems that it doesn’t work the way I want it to. Also side note: I put 100 on z axis just because I want to show what my blueprint is capable of. I obviously don’t want to get launched in the air when I get hit I want to get knocked back in the opposite direction I got hit from.

I’ve never tried LaunchCharacter. I think I may try it though. What I did was use the AddImpulse function of the movement component. It has its own faux-physics functionality. I can attest that this method at least works.

The tricky part is getting the character to animate like he’s stumbling. Without a specific stumble animation I had to cause the state machine to glitch out a little and use the walk blendspace at a higher play rate and limit the input velocity. It looks pretty good (considering) and the animation can be replaced later.

You think you can show a screenshot of your blueprint?

Do you mean just the AddImpulse part? The entire thing is pretty complex due to the way I intentionally glitch the walk animation, plus the code for getting knocked out of cover. I don’t want to confuse things. The AddImpulse part looks like this:

The max node is there because my impacts accumulate over a short moment and if they reach a threshold he gets knocked back. Sometimes they can add up to an unrealistic amount of force so I use the max node to keep it looking good. You should be able to just plug your vector straight in.

It should work. Try using a higher magnitude of force or check the “Velocity change” box to make sure it’s doing something.

I plugged the add impulse node and removed launch character node but it does nothing. I don’t get knocked back at all.

Nope it’s not working the way I want it to. I just need it to launch me in the opposite direction. But when I use add impulse it just launches me in the air and I’m stuck up there. So I used y axis but it’s not moving me. X axis will probably do the same. That’s why I want to use launch character instead of add impulse cause that was the closest I got to what I wanted. All I need to know is how to make it push me in the opposite direction not just in one specific direction.

Multiplying a vector by a negative number inverts it so that makes it “the opposite direction”. You have a negative number in the multiply so that is inverting the impact vector.

Maybe instead of using the hit normal, use the velocity vector of the impacting actor.

Okay so I added a negative number and it works for that one direction but when I go around him I get pushed towards him. There’s gotta be some way where if I get hit I just stumble backwards and not in a -500 X axis direction or something, y’know.

How are you hitting the object? A melee Weapon? Try casting from the hit actor to the object and add the “add impulse” to the character movement component. The way i set it up my self is getting the “Actor forward vector” and Multiply it by a negative number and setting that as the velocity

Hope that helps.

No I’m getting hit by an enemy actor (Getting touched). But I’ll try that out.

Yeah, actually. The hit normal is not the incoming vector, it’s a surface normal in local space IIRC. Whatever is hitting your character, use that velocity for the hit vector.

Don’t use the Hit Normal. That’s your problem. You will never be able to use it as an accurate impact vector. Use the velocity of the projectile (or whatever it is). If it’s using a projectile movement component then you may run into another (fixable) issue. So make sure you add a PrintString that displays the vector you pass into Launch. Again tho, it can’t be derived from the Hit Normal, that is for determining the angle of impact of the collision objects, not the vector of the incoming force.

Yeah It might be worth putting some print strings to see what you are hitting from event hit. good luck

Can you show an image of your blueprint? I did it in my own way and it’s not working. I hope this post of mine didn’t get posted twice cause I sent this response but it didn’t go through for me.

Unfortunately i’m not at my office atm. In anycase my situation is abit different because i’m using a melee weapon that applies the impulse. I can try hash something similar out. might take abit. In the mean time, try Jin_ve’s suggestions

So what do you want me to do then? I won’t use hit normal so what should I connect multiply vector to? Remember, the enemy is only touching me, not shooting a projectile or smacking me across the head with a baseball bat. Remember, my blueprint looks like this, I connected that multiply vector to hit normal but I’ll remove that obviously, so what should I connect that multiply vector to?

https://i.imgur.com/VRjBar0.png

To test what Samuel is saying, instead of getting the vector from HitNormal, drag from “OtherComp” and call GetForwardVector. Plug that into your multiply and see if you get any effect. Forward might not be the correct vector to use but it should at least be closer to what you want because it’s in world space. If it’s not right, try GetRightVector.

This is just for characters bumping into each other?

OK so Samuel was on the right track then. It’s not about the velocity of the other actor, it’s some kind of force-field bounce-back effect.