How to lauch charachter in a certain direction?

I created an explosion and I want the player to be launched in a direction depending on the actual explosion. I just don’t know how I can get the direction in order to launch the player. Any help is appreciated.

normally you would do Add radial impulse for the explosion and have simulate physics on.
If not that. Sphere trace, then get world location of explosion and location of overlapped player and do find look at rotation->forward vector->normalize->launch character

I cant seem to find “Find Look at Rotation” in c++.

AMy*player = Cast((Hit.GetActor()));
if (player) {
FVector sik = player->GetActorLocation() - GetActorLocation();
float orosbu = sik.Normalize();
float pic = sik.Size();
LaunchCharacter(sik.GetSafeNormal(orosbu)*2000/pic, true, true);
}

What is the issue here?

Normalize() normalizes the vector or leaves it unchanged if the vector could not be normalized. The function itself will return a boolean depending on whether if the normalization was successful or not.

GetSafeNormal() normalizes the vector or changes it into a directionless zero-vector if the vector could not be normalized. The input parameter is tolerance (I’ve mixed this up before due to how some of the other vector operators work), the default value should do just fine so no input parameters are needed.

In other words, both functions do the same thing; their behaviour differs only when the vector could not be normalized. You should only need to use one of them, not both.

LaunchCharacter(sik.GetSafeNormal()*2000/pic, true, true) should work, without ever needing to use Normalize() or “orosbu” at all. The value for launching the character might end up being too low, though I think what you are trying to do is to scale the magnitude of the force by character’s distance from the explosion.

You’d still want to assign some default direction in the case where the vector could not be normalized.

I’d recommend using UE4’s style (like capitalized variable names) for better readability and consistent style.

Thanks for the explanation. I actually forgot the"player->" part. Because of that it didnt work. So thanks yall.