How to only increase forward movement speed of character?

I thought of a few solutions, but can’t verify at the moment.

  1. Add enum MovementDirection to character,
    pros: easier management
    cons: performance loss

  2. Add bools bIsMovingForward and bIsSprinting

if (bIsSprinting)
	if (bIsMovingForward) MoveSpeed *= 2.0f; // forward sprinting
	else if (!bIsMovingForward) MoveSpeed *= 1.5f; // Meaning either strafing or NE, NW movement

pros: easier on character movement
cons: harder to implement in character

  1. Add extra movement input from character on tick if sprinting

void Tick(float DeltaTime) override
	if (bIsSprinting && bIsMovingForward) MoveForward(1.0f);

pros: easiest to implement
cons: performance…

I’m not sure if they’ll even work, but if you guys know a better way, please post it here :smiley:

ShooterGame does it. Easy peasy, you just set the max movement speed. You can just download and have a look at it.

What I did was created my own Subclass of CharacterMovementComponent and overrided “GetMaxMovementSpeed()” (I believe is the name) and copied the original code into that code. Which is just a big switch statement checking movement modes. I added a if(bSprinting) check inside the Walking/crouching section of the switch, and returned sprint speed if sprinting. Very simple and flexible and it all works properly with the rest of the system.