Hello !
I am trying to push back a character (other player) after they get hit by a projectile. Is there an engine way of doing this? I have tried launching the character which apparently sets characters state to “Falling”, so it doesn’t work for me. I am currently trying to give character an impulse and the problem with that is the character falls over. Can I fix the issue of the character falling over? Or should I forget the impulse thing at all?
For clarity, my end goal is: launch the character in some direction after getting hit, so the initial force the character receives is large and it slowly gets the grip back (the sliding speed reduces) until the character is able to walk again
You can mass copy/paste nodes from here but you’ll need to clean it up.
To control push power, multiply Reaction Velocity before setting it after Do Once. Currently it’s a direct translation of the projectile’s velocity. The Interp Speed will affect how quickly we recover from the slide, slow down. For more granular control, the interpolation method can be improved by sampling a predefined curve.
The above produces this:
Known issues - due to the method used, it will also produce this (exaggerated the power to demonstrate):
A couple of ways to solve it:
when hitting simulating obstacles, push them away, too and keep going in the original direction
and / or
when hitting a stationary obstacle, get the surface normal and slide along its right vector. So when we arrive at its edge, we’re still moving in a logical direction.
or
stop sliding when an obstacle is hit - the easiest fix but may be undesirable due to the game mechanics expectations
Also, never tested it with something applying additional movement input.
It works “almost” perfectly, thank you for the response.
The only thing I would like to change with this implementation is that I have to put this logic in character class. I tried moving it to the projectile itself, but couldn’t manage to make it work (maybe because I’m a noob), I want to achieve that because in my game I will have lots of projectiles that may hit the character and some might not even push them back, so I will have to make long casting spree to find out which projectile just hit him. So is there a way to move this same logic in the projectile itself? Or is it too much work and I’d rather stick with casting and figuring out which projectile it is? (The workaround I’m thinking is to make a base class for all pushback projectiles and check if the one hitting the character is child of that base class, is this a proper solution? of course I’d rather move this code to projectile if possible )