Some one good with math? Impulse direction based on impact location

Hello,

I want to push the enemy player based on where I hit him from.
I have 3 attacks: left + right swing + stab.
E.g. if I swing from the right he should be pushed to the left. I can’t get the math working.

Right now I’m doing it this way, but it gives very inconsistent results:

1 Like

If I’m not mistaken, couldn’t you just do this?


The offset should cause it to always go up. Change 100 to something higher if you want them to go higher or lower it if you want something less intense (which I’m betting you’ll end up needing to do)

2 Likes

Hey @MajekPL

In this case Normalize with such a small value could cause a problem. What happens if you use 0,1? And you could also try GetUnitDirection.

1 Like

Thanks a lot this works so much better! There are still instances when the ball just jumps a little and not in the right direction though. Any idea what it could be?

Ah, GetUnitDrection seems to work the same as FindLookAtRotation->GetForwardVector. I implemented the solution from above and it definitely works better, than my old approach. Thanks!

1 Like

Hey @MajekPL

do you still have those problems?

There are still instances when the ball just jumps a little and not in the right direction though

You could check the HitLocation and the LaunchVelocity with a LineTrace to show the vectors / or SphereTraces for the different points.

In this case it looks like your a using your player as the Target for your LaunchVelocity?



2 Likes

I’m actually using the hit actor as the target for the launch character. That’s why I’m confused as why it would react that way. I will put your previous post as “solution” as that one helped me for 95% of the swings. Thanks for your help!

1 Like