How to control movement while on jetpack in air?

It was a simple youtube tutorial which just raises the character in the air, but I would also like to control the movements. Code attached below:

void AMyProjectCharacter::Tick(float deltaTime)
{
	if (isSpaceBarDown)
	{
		GetMovementComponent()->Velocity.Z = maxRiseSpeed;
		GetCharacterMovement()->SetMovementMode(MOVE_Falling);
	}
}
1 Like

By default. the Character falling movement mode allows some lateral velocity - I suggest you tweak its settings to allow for more of the input to allow movement while falling.

you can also tweak this at runtime, say, if you only wanted the extra falling movement speed to apply while using the jetpack

Yes that is my question, I am still not adept at c++, how would I tweak it?

1 Like

Take a look through the properties of the character movement component in the details panel of your character - Try changing some that sound like they’ll give you the effect you want. Then find those same properties in code and tweak them that way.

1 Like

I tried it this way, but it doesnt seem to work either

void AJuniorProgrammerTestCharacter::Tick(float deltaTime)
{
	if (isSpaceBarDown)
	{
		GetMovementComponent()->Velocity.Z = maxRiseSpeed;
		if (maxRiseSpeed != 0)
		{
			AddMovementInput(GetActorForwardVector(), maxRiseSpeed);
			AddMovementInput(GetActorRightVector(), maxRiseSpeed);
		}
		GetCharacterMovement()->SetMovementMode(MOVE_Falling);
	}
}
1 Like

You really don’t want to be setting the movement mode every frame. You need to be doing this using input actions

1 Like

How do I do that?

Input event pressed / released. I also recommend following Epic’s style when writing code; as an example, the “isSpaceBarDown” would be “bIsSpaceBarDown”.

Though probably rather than that; you should have something like bIsJetPackActive which is set by the spacebar input events. And you’d likely want to turn that into an enum in the long run, if the character has multiple mutually exclusive states of movement.