Walk Toggle

So rather than press a key continually for walking I implemented a Walk Toggle so that I can see the different ‘Jog’ and ‘walk’ animations.

ShooterCharacter.h

	void ToggleWalk(void);

	UPROPERTY(EditAnywhere)
	float WalkRate = 0.5f;
	bool bWalk = false;

ShooterCharacter.cpp

...
void AShooterCharacter::ToggleWalk(void)
{
	bWalk = !bWalk;
}

void AShooterCharacter::MoveForward(float AxisValue)
{
	if (bWalk) { AxisValue *= WalkRate; }
	AddMovementInput(GetActorForwardVector() * AxisValue);
}

And added an ActionMapping Walk mapped to the Z key. Updated the SetupPlayerInput function to add the binding to the ToggleWalk() function.

	PlayerInputComponent->BindAction(TEXT("Walk"), EInputEvent::IE_Pressed, this, &ThisClass::ToggleWalk);
3 Likes

Incredible !!!

Privacy & Terms