How can I offset a Vector Location?

I have a line trace that hits an enemy character. After that, I either apply a “Launch Character” or when it’s dead I use a “Add Impulse at Location” where the velocity or hit location is the one I get from the line trace.

This lets me either push an enemy back or let it fly through the air as a ragdoll.

This method works most of the times, but something seems off. Occasionally, enemies don’t get pushed backwards but instead left or right. Ragdolls don’t fly directly backwards but also slightly to the side, which just looks off.

I’ve tried many things, but I think what it comes down to is that the hit location vector from the line trace is just too close to the enemy and that makes it seem off.

So my question is how can I offset the vector so that it is not exactly the location where the enemy is hit but slightly before the enemy is hit?

Thanks a lot!

You can do two things:

  1. Create a box around the thing being shot, and have the line trace hit that instead of the actual thing/mesh.
  2. Do some vector math to get the vector point just before the character.

First one is what I would do, personally. But here’s how I did it with vector math:

(begin vector+end vector) / 2

That will get you the midpoint of the trace. Simply redo it to get the vector closer to the object.

Thanks for your answer. I’m not sure if this is actually solving the issue for me without creating new ones.

  1. If I create a box around the enemy, the actual hitbox of the enemy would increase, which is undesirable.
  2. The vector math you’re using is taking the half way point between the player and the enemy, which is also undesirable. The hit force and accuracy would change according to how far away a player is.
  1. You would create custom trace/collision channels. So, your projectile would hit the “impulse” box, and one of two things can happen: The projectile hits the actual target, and you would use the impulse hit vector to add impulse… Or you miss the actual target, and the impulse hit vector is not used.
  2. I mentioned at the end there that you would redo the math to get closer to the target. For example: (Math) gets you to the halfway point. But, (Math+Math) gets you to 75% the distance from you to the target. So, just repeat the math until you reach your desired range. Made a BP to show you: (also, that last part should be 87.5%)
    70135-
    An ever better way would be to make a nice clean function to do it for you and just define the amount of iterations

Thank you so much, but for some reason the image doesn’t show up :frowning:

Imgur