I am trying to recreate the strafing movement in Spartan Assault. But I can’t get the character to go back to it’s idle pose when the character is not aiming because my controller right thumbstick does not reset to zero. Basically when I stop pressing on the right thumbstick the character should go back to the idle pose. Just like in spartan assault. My code is below I am using an if else statement. I am new to C++ and UE I have only been doing this for over a year now.
void ATestController::ControllerAim(const FInputActionValue& Value)
{
FVector2D InputValue = Value.Get();
if (InputValue.X != 0.0f)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, FString::Printf(TEXT("InputValue: X = %f"), InputValue.X));
TestCharacter->bIsAiming = true;
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, FString::Printf(TEXT("bIsAiming: %d"), TestCharacter->bIsAiming));
AddYawInput(InputValue.X);
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, FString::Printf(TEXT("InputValue: X = %f"), InputValue.X));
TestCharacter->bIsAiming = false;
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, FString::Printf(TEXT("bIsAiming: %s"), TestCharacter->bIsAiming ? *FString("True") : *FString("False")));
}
}
According to the on screen debug message it is not resetting. I my animation blueprint I have the character going from Idle to strafe if IsAiming is true and from strafe to Idle if IsAiming is false.
Here is my SetupInputComponent
void ATestController::SetupInputComponent()
{
Super::SetupInputComponent();
UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent);
if(EnhancedInputComponent)
{
UEnhancedInputLocalPlayerSubsystem* EnhancedSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
if(EnhancedSubsystem)
{
EnhancedSubsystem->AddMappingContext(IC_Character, 0);
}
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ATestController::Move);
EnhancedInputComponent->BindAction(ControllerAimAction, ETriggerEvent::Triggered, this, &ATestController::ControllerAim);
}
}
here is a clip
Any help would be appreciated.