How to push (knockback) a migrated default ThirdPersonCharacter using the FirstPersonTemplate weapon

Hi guys,

I use a FirstPersonTemplate and I want to be able to push (knockback) an AI when I shoot at him. For this I first set the sphere’s (FirstPersonProjectile) CollisionPreset to PhysicsActor and it seems that it partially works. Meaning that the AI is pushed back (knockbacked) but only when I hit him in the legs.

The AI was migrated from the default ThirdPersonCharacter and I’m not sure if it’s the collision box not properly set or perhaps something else. I’ve made some research and even made a Physics Asset but it’s not working and I don’t know if I have to link them or how to proceed from here.

Does anyone have any advice on this issue ?

Any feedback is appreciated as I’m new to this and don’t know what I’m missing.

Many ways to do this.
why not detect what the projectile collides on on the projectile BP, and add impulse to the object if it is of the correct/expected class type?

You probably want this node

Feed it the impact location

Use the object capsule component as the primitive target.

Thanks for the idea. I looked around in the projectile BP and saw that there is already an Add Impulse at Location that is used.
It works when shooting at an object but when shooting at a character it doesn’t seem to work.

Any idea how to make that work ?

For a character use ‘launch character’ node instead :slight_smile:

Hmm, I can’t seem to find ‘launch character’ node. Do I have to make a variable or something like that ?

Hmmm not in front of a computer at the moment to remember exactly.

right click in the blueprint editor then untick ‘context sensitive’ and search for launch. It should pop up in that list then. You’ll probably have to drag a get node for your character component into the blueprint and connect it to the launch character node :slight_smile:

EDIT: or do it the other way round and place a get node from your character component and then drag a pin out then search for launch character

Here’s the API link if you need it: http://api.unrealengine.com/INT/Blue…ter/index.html

If I answered the question correctly first time round I wouldn’t have to do so many edits… :slight_smile:

I forgot to say that the launch character function comes from the character movement component i believe so that’s the component you’d want to drag a get node out for.

Thanks for the details, I found ‘launch Character’ but I don’t think I have that character component you’re saying. I’ve tried some things but none worked.
I’ve attached a screenshot for easier context. I’m not sure where do I need to connect it in order to make this work.

Can I ask of you to help me with this, when you have the time ?

Thanks again!

No worries do us a screenshot that shows your component list on the left hand side and that should be enough to work it out from that

There you go :slight_smile:

Drag out the hit and find the hit result node or break the hit result pin.
What you hit should be in there allowing you to determine or te see t if it was an actor or an object.

Hmmm ok i thought you said you had derived it from the character but it doesnt look like thats the case looking at the screenshot :slight_smile:

ah…thats the projectile class…man im losing the plot today :slight_smile:

ok this might be a bit more complicated. So on that hit result you’ll need to find if the other actor has a character movement component, get a reference to the character movement component then plug that into tje launch character.

be easier to show you with a screenshot but im not near a computer at the moment. I’ll try do it whem i get home :slight_smile:

EDIT: actually grab us a screenshot of your AI class aswell with the list of components showing. Might aswell make sure its using the Character Movement Comp.

Alright, so here’s the basic AI I’ve done. He’s just going to follow the player when in his vision.

Coolio that AI class has the character movement comp so launch character is defo what you want to use. I’ll do you a screenshot of the setup when i get home

Ok so maybe that wasn’t as complicated as I remember :slight_smile:

The bit in red on the screenshot is the extra bit.

  • From your Branch node drag out the false pin and place a ‘Cast to Character’ node.
  • From the ‘Event Hit’ node drag the ‘Other’ pin and connect it to ‘Object’ on the ‘Cast to Character’ node.
  • From the ‘Cast to Character’ node drag the ‘As Character’ pin and place a ‘Launch Character’ node.

Snorted.

maybe put some more sensible values for the velocity than the ones I put in the screenshot :wink:

I don’t know if you’ve set your collision channels yet but if not you’ll have set the projectile to block the Pawn channel and the AI pawn character needs to have ‘Simulation Generate Hit Events’ on.

Nice ue4 version of Bat the Penguin :stuck_out_tongue:

Out of curiosity, wouldn’t input at location and a proper PHAT config on the enemy allow for localized hit reaction?

Yeah can apply physics impulses to bones to get nice hit reactions. You’d have to switch on physics for that bone/s though, sort of half ragdoll state.

for example could set on physics for the head bone when hit and watch it flop about.

that sounded wronger than i meant it to…

Thanks a lot savagebeasty !!!

It does work :slight_smile: The only weird thing is that sometimes he doesn’t get knocked back when he’s coming straight at me and I’m shooting directly right at him, but that probably is something else.

Otherwise I did played around with the values and it works nicely :smiley:

no worries :slight_smile:

yeah obviously its a bit of a simplistic solution you’d need to refine it a bit, you’ll probably find you get hit by your own bullets sometimes and it sends you flying, you’d need to add a check to make sure you’re not colliding with yourself really. The magical world of game programming :slight_smile:

Not sure about the coming straight at you bit, i suppose if the AI is currently at a high velocity and you hit them with the opposite velocity the two cancel each other out a bit. Might be worth upping the velocity values or maybe try ticking those ‘override x, y, z’ bools on the launch character node. I think then they’d ignore the pawns current velocity and you’d get a more consistent ‘push’. I’ll be honest I’m not sure if that’s what those override bools do from memory. I’d guess they are like the apply impulse nodes where you can tick the ‘velocity change’.

If I may ask another related question, can I use the same thing to make a box, that I can already pick up and throw at the AI, to push him (knockback) the same way ?
Right now, when throwing a box at the AI character he doesn’t get knocked back.

Thanks again and I really appreciate the help!

yeah don’t see why not the launch character node is just a function you can call it anywhere really :slight_smile:

You could either make a blueprint for the box and set it up there or put the logic into the AI pawn as a catch all. Probably want to add some extra checks in there if you put it in the AI pawn as you wouldn’t want to send the ai flying when they touch a physics object that isn’t moving for example. Again the joys of game programming…you have to think of all the ways that something could interact with another object and plan for it. :slight_smile: