Best practice to stop movement until new input arrives (sitting down)

Simple scenario: sitting down.

Now, to sit down, things for me should go like this:

  • Interact with chair
  • Trigger a boolean (isSitting) in the player character, which the AnimBP will use for the animation
  • Do not allow the player to use any movement input during the animation
  • Play the standing up animation when the player tries to move again, which means the movement input is technically being used for a different purpose (triggering again the boolean isSitting)
  • Enable normal movement input

But here’s the problem. Everything goes right until I try to use movement inputs to stand up instead of moving. I can’t outright disable the input movement because I still need it to disable the sitting down, but this doesn’t work in my controller:

void AProtagonistController::MoveForward(float axisValue)
{
    if(aControlledCharacter->GetIsResting() && axisValue)
    {
        aControlledCharacter->StopResting();
    }
    else
    {
        FVector playerForwardVector = aControlledCharacter->GetActorForwardVector();
        aControlledCharacter->AddMovementInput(playerForwardVector,axisValue);
    }
}

Because axisValue is always equal to 0, which also makes me wonder how the heck AddMovementInput works to begin with.

This is a great use case for Input Mapping Contexts (IMC).

For your normal movement, assign an IMC that handles all of your common inputs and assign them to Input Actions (IA). When you take a seat, you can remove that IMC and then apply a different IMC that only takes an IA for getting out of the seat.

Take a look at Epic’s documentation on Enhanced Input.

I should’ve asked this question long before wasting almost 2 hours thinking of the cleanest way to achieve this. Thanks!

1 Like

You’ll remember the answer better now that you’ve struggled, though, and you’ll know that the IMC is a superior method because of the struggle you’ve endured.

Never regret your struggles! :smiley: