I don’t have Unreal open right now, but it should be possible to create an action mapping on pressing Shift. It should not be affected by whether you have W down or not.
So:
- Set up a new Action Mapping called “Sprint” on Left Shift under Project Settings > Input:
-
Add two functions to YourCharacter.h and YourCharacter.cpp to start and stop sprinting, and bind them in SetupPlayerInputComponent:
// YourCharacter.h
public:
void SprintStart();
void SprintStop();
void SetupPlayerInputComponent(UInputComponent * PlayerInputComponent) override;// YourCharacter.cpp
void AYourCharacter::SetupPlayerInputComponent(UInputComponent * PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);InputComponent->BindAction(TEXT("Sprint"), IE_Pressed, this, &AYourCharacter::SprintStart); InputComponent->BindAction(TEXT("Sprint"), IE_Released, this, &AYourCharacter::SprintStop);
}
void AYourCharacter::SprintStart()
{
GetCharacterMovement()->MaxWalkSpeed = 800.f;
}void AYourCharacter::SprintStop()
{
GetCharacterMovement()->MaxWalkSpeed = 600.f;
}
Here I’m just hardcoding the movement speed to 800 when sprinting and to 600 when not sprinting, but it should give you a starting point.