I am working on the SimpleShooter course and wanted to try implementing a sprint function. When the left thumbstick or left shift is pressed, the MaxWalkSpeed is set to 600 and when the action is released, the MaxWalkSpeed is set back to 300. I noticed when releasing the Sprint button, the animation is instant from jog to walk. After doing some research, I learned how to use Lerp in blueprints and it looks perfect, however I can’t seem to get it to work in C++.
Here is how I implemented it in Blueprints
and here’s the Sprint, StopSprinting, and AdjustMaxMoveSpeed functions in my c++
void AShooterCharacter::Sprint()
{
#if 0
TargetMovementSpeed = 600.f;
//GetCharacterMovement()->MaxWalkSpeed = TargetMovementSpeed;
#endif
}void AShooterCharacter::StopSprinting()
{
#if 0
TargetMovementSpeed = 300.f;
//GetCharacterMovement()->MaxWalkSpeed = TargetMovementSpeed;
#endif
}void AShooterCharacter::AdjustMaxMoveSpeed()
{
#if 0
float CurrentWalkSpeed = GetCharacterMovement()->MaxWalkSpeed;
float Difference = abs(CurrentWalkSpeed - TargetMovementSpeed);
if (Difference > 1)
{
CurrentWalkSpeed = FMath::Lerp(CurrentWalkSpeed, TargetMovementSpeed, 0.1f);
}
#endif
}
the if/endif is just there for me to turn on/off while working on the next parts of the course. in the header, TargetMovementSpeed is a float with default value 300.f. My includes are all there and it compiles. The character just never sprints when using AdjustMaxMoveSpeed. When I use
GetCharacterMovement()->MaxWalkSpeed = TargetMovementSpeed;
it works with the bad transition.
Any advice would be great and if you need any more info, I would be happy to give it.