Leap/Launch pawn forward

You will have to use the camera orientation instead of the actor’s forward vector (forward vector is orthogonal to the xy-plane if I recall correctly), e.g.

FVector viewLoc = GetPawnViewLocation();
FRotator viewRot = GetViewRotation().GetNormalized();
FVector forceVector = viewLoc + viewRot.Vector() * 1800.0f;

P.S. You might need to adjust the retrieved ViewRotation’s pitch to be larger than zero to handle the case when the mouse is pointing downwards.

Hello,

I’m trying to make the pawn leap / jump forward in the direction that they’re facing. So if the player is looking upwards and this function happens, they will be pushed with velocity upwards (because it’s the direction they’re facing).

Right now, I have the code below which works, but it doesn’t work for all directions, it’s just forward - I’d be greatful if somebody could point me in the direction of how I can change this to work to the desired effect above.

const FVector ForwardVec = GetActorForwardVector() * 1800 + FVector(0, 0, 1.0f);

GetCharacterMovement()->SetMovementMode(MOVE_Flying);
LaunchCharacter(ForwardVec, true, true);

Thanks.

You are excellent! This put me on the right path. For those who are curious, this is what worked for me.

FRotator viewRot = GetViewRotation().GetNormalized();
FVector viewDir = this->GetActorLocation() - this->GetPawnViewLocation();
FVector forceVector = viewDir + viewRot.Vector() * 1800.0f;


GetCharacterMovement()->SetMovementMode(MOVE_Flying);
LaunchCharacter(forceVector, true, true);

This was for a multiplayer game fyi.

Thank you Staticvoidlol!