Download

Character Go Mad Slow

Here is my void function thingy for sprinting:


Help appreciated

So… What about increasing the multiplier’s value?

@STRiFE.x Here’s the thing the value is set to 2 and works fine but after I move in any other direction then forward it slows down every time I press the shift button

Your problem might be … pressing the sprint key should just toggle the sprint multiplier. The move keys/functions should factor in the sprint multiplier. Our working sprint code looks like this:



void AFirstPersonCharacter::StartSprinting()
{
    _sprintMultiplier = MOVE_MULTIPLIER_SPRINTING;
}

void AFirstPersonCharacter::StopSprinting()
{
    _sprintMultiplier = MOVE_MULTIPLIER_WALKING;
}

void AFirstPersonCharacter::MoveForward(float value)
{
    AddMovementInput(GetActorForwardVector(), value * MOVE_FORWARD_RATE * _sprintMultiplier);
}

void AFirstPersonCharacter::MoveRight(float value)
{
    AddMovementInput(GetActorRightVector(), value * MOVE_RIGHT_RATE * _sprintMultiplier);
}


Not sure about your specific mechanics, but in this way toggling the sprint key while standing still and nothing happens. When you press a move key is when sprint / walk multiplier are factored in.

Okay I worked out (Kinda) so it works however when I try and sprint in direction that I have disabled sprinting for. Etc left, right, back it stills divided the max walk speed even though it hasn’t been increased.

Put the whole sprinting logic in Tick instead. Don’t worry about it not being event based. I suggest that you watch some videos on youtube about the basics of programming though. The code below assumes that you have a Sprint and MoveForward input, as well as two float variables SprintSpeed and WalkSpeed in the header file.



// ...pseudo code, may have errors!

void ANinja::Tick(float DeltaSeconds)
{
     // Update our movement speed every frame.
     UpdateMovementSpeed();
}

void ANinja::UpdateMovementSpeed()
{
     // Check if the character is controlled. This means that GetController is set, and will not
     // return a nullptr. Assumption is made here that only the player can possess this character.
     if (IsLocallyControlled)
     {
          // Check if we are running.
          bool bIsRunning = GetController<APlayerController>()->IsInputKeyDown(TEXT("Sprint")) && GetInputAxisValue(TEXT("MoveForward")) > 0;
          
          // Update the movement speed.
          GetCharacterMovement()->MaxWalkSpeed = bIsRunning ? SprintSpeed : WalkSpeed;
     }
}