How to launch a character both up and forward

I’m trying to create an aerial dodge mechanic that gives the character a slight vertical boost and launches them out of the way. I initially did this by adding an additional call to jump if the character is in the air and then launch them afterwards, but it seems the jump doesn’t persist if I do this and the character just shoots outs. Is there any way I can launch the character in a slight arc?

Current code:

void APlayerCharacter::StartJump()
{
	if(GetCharacterMovement()->IsFalling())
	{
		GetCharacterMovement()->JumpZVelocity = 150.f;
		Jump();
		const FVector ForwardDirection = this->GetActorRotation().Vector();
		LaunchCharacter(ForwardDirection * AerialDodgeDistance, true, true);
		GetCharacterMovement()->JumpZVelocity = 600.f;

	}
	
	else
	Jump();
}

You can either do some geometry with the forward vector (pitch it up, average it with the UP vector, etc) or cheat and just adjust the Z vector you calculate with it (which would have been 0 unless you allow character pitching):

FVector LaunchVector = this->GetActorRotation().Vector() * AerialDodgeDistance;
LaunchVector.Z = 150.f;
LaunchCharacter(LaunchVector, true, true);

Can I ask how you’d go about calculating that geometry and implementing it?

I just position an arrow component and use its forward vector. if you want to change the trajectory just rotate the arrow component. this way there is no guessing and no extra code - just using what is already present in the engine

2 Likes

It’s your game, what do you want it to do?

Based on what you’ve said, a possible approach:
Get current input vector
Pitch it up some amount
Normalise and then scale
Apply Launch.

Which would look something like (BP obviously, easy convert):

That’s what I was was asking, generally how to manipulate the vector. More specifically, I’m trying to get a trajectory that shoots up and out, moving laterally for a distance before falling off. Like so:
Screenshot (853)

How to manipulate a vector and how to get a trajectory like X are two completely different questions.

If using LaunchCharacter() for this, then you can set a initial velocity, after that gravity, friction and breaking decel will do the ‘falloff’ and you would need to tweak them (along with the initial launch vector) to get the desired trajectory.

If you want absolute precision with the trajectory taken then you probably don’t want LaunchCharacter(), and could maybe look into root motion sources.

1 Like

FVector JumpUpwardDirection = GetActorUpVector(); // Get the character’s upward direction
LaunchCharacter(JumpUpwardDirection * 600.0f, true, true); // Apply the launch with the desired strength