Download

How to add proper "sprinting" to your pawn

Hey guys. I recently figured out how the pros do this, so I’m going to share this with ya guys :D. OK, now this is the basic principle behind proper “sprinting”.
Only pawn’s forward move speed increases, while right, left, and backward speeds stay the same.

Now how to implement this is pretty simple, but unfortunately you won’t be able to do this to a Character. You’ll need to make your own pawn.



// Global movement speed modifier
float GlobalSpeedModifier = 1.0f;

// Forward movement speed modifier
float ForwardSpeedModifier = 1.0f;

// Right movement speed modifier
float RightSpeedModifier = 1.0f;

// Backward movement speed modifier
float BackwardSpeedModifier = 1.0f;

// Left movement speed modifier
float LeftSpeedModifier = 1.0f;

AND do this for movement code:


/** Handles X axis movement */
void MoveForward(float Value)
{
if (Value != 0.0f)
{
Value *= GlobalSpeedModifier;

FRotator Rotation = Controller->GetControlRotation();
Rotation.Pitch, Rotation.Roll = 0.0f;

const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);

if (Value > 0.0f) AddMovementInput(Direction, Value * ForwardSpeedModifier);
else if (Value < 0.0f) AddMovementInput(Direction, Value * BackwardSpeedModifier);

// and the same for MoveRight() with Right and Left speed modifiers and GetScaledAxis(Y); Zero out yaw and pitch instead
}
}


Now when sprint is pressed / released, simply do this:


/** Called when sprint pressed */
void OnStartSprint()
{
ForwardSpeedModifier = 1.5f /* or whatever else */;
}

/** Called when sprint released */
void OnStopSprint()
{
ForwardSpeedModifier = 1.0f;
}

And if you don’t know how to make your custom pawn move, check out this gr8 tutorial, and hope this helped.

Just FYI, I was struggling for weeks to figure this out with various attempts at solving this until I finally mailed Splash Damage (thx btw). Just posted this here in case anyone else is frustrated that no other sprint tutorial out there increases forward speed only.

And feel free to re-post this on the wiki, just put a link to this thread :slight_smile: