How can I launch a character forwards?

Hey! I am working on a momentum based jump system. It works perfectly fine, except for the fact that the x direction does not adjust to my player. That means that when I am facing a certain direction, my character is actually propelled backwards, rather than forwards. Anyone know how I could prevent this? It would be super helpful! Thank you in advance.

Here is my code:

void AFirstProjectCharacter::InitJump()
	FVector launchVelocity = FVector(plMomentum, 0, plJumpVelocity);
	if (CharacterMovement->IsMovingOnGround())
		dJumped = false;
		LaunchCharacter(launchVelocity, false, true);
		if (!dJumped)
			LaunchCharacter(launchVelocity, false, true);
			dJumped = true;

#Various Info

To get the forward vector of the Character, to launch them along their current facing direction

#option 1

const FVector ForwardDir = Character->GetActorRotation().Vector();

#option 2

const FVector ForwardDir = Character->GetRootComponent()->GetForwardVector();

#Applying Force along Forward Direction

Character->CharacterMovement->Velocity += ForwardDir * 30000; //replicates automatically, if done on server

#Adding Vertical

const FVector ForwardWithZ = (ForwardDir + FVector(0,0,1)).SafeNormal(); //in case forwarddir had some Z

#Adding Vertical not world axis aligned

const FVector ForwardWithUp = (ForwardDir + Character->GetRootComponent()->GetUpVector()).SafeNormal()

#Adding Vertical with Speed and Z with Speed Separately

const FVector TotalForce = ForwardDir * ForwardSpeed + FVector(0,0,1) * UpSpeed;

Character->CharacterMovement->Velocity +=TotalForce; //replicates if done on server

where the speeds are floats


you could use LaunchCharacter instead of my Velocity += Dir * Speed method,

the fundamental thing is you need to calculate the jumping direction , forward and vertical, more precisely.

Adapt the above basic formulas to your momentum-based system and you should be good2go.


1 Like

const FVector ForwardDir = FirstPersonCameraComponent->GetForwardVector();

	const FVector AddForce = ForwardDir * plMomentum + FVector(0, 0, 1) * plJumpVelocity;

	if (CharacterMovement->IsMovingOnGround())
		dJumped = false;
		LaunchCharacter(AddForce, false, true);

Seems to be working perfectly! Thank you very much :slight_smile:


Yay! Glad you got it work!

(please check mark my answer if you see this so Epic knows the issue is under control)

I did. For some reason when I add a comment, it just marks it as not solved

i have done the sliding using the above method its working fine,but when i put multiplayer the slide increases as the player increases how to fix that?