I am trying to create a movement script using two alternating button to addMovement to player
PsudeoCode
if (APressed && BReleased) || (BPressed && AReleased)
{
PlayerMovesForward
}
I so far from an accurate thought on how to approach this. Any guidance would be greatly appreciated.
Hi
I was able to convert the functionality of your (exceedingly helpful) blueprint into C++.
I’m still having a problem with the “button mashing” element that I am trying to implement
Currently, if A or B is pressed the player moves forward. I trying to get the player to move forward only when A and B are pressed in consecutive succession (e.g A, B, A,B).
I’m thinking about those old track and field games where you have to press “Left Arrow” and “Right Arrow” on your keyboard super-fast for your Runner to gain momentum and move forward.
This is where I am so far…
void AMainPlayer::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
InputComponent->BindAxis("APressed", this, &AMainPlayer::APressed);
InputComponent->BindAxis("BPressed", this, &AMainPlayer::BPressed);
InputComponent->BindAxis("Yaw", this, &AMainPlayer::Yaw);
InputComponent->BindAxis("Pitch", this, &AMainPlayer::Pitch);
}
void AMainPlayer::APressed(float amount)
{
if (Controller && keyAlternate == false)
{
AddMovementInput(GetActorForwardVector(), amount);
}
keyAlternate = true;
}
void AMainPlayer::BPressed(float amount)
{
if (Controller && keyAlternate == true)
{
AddMovementInput(GetActorForwardVector(), amount);
}
keyAlternate = false;
}