Analog values from Xbox Controller Sticks

Hello!

I would like to retrieve the analog input from the analog sticks of a Xbox controller.

I have the following at the moment:

void MyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent) 
{
    InputComponent->BindAxis(TEXT("Yaw"));
}

void MyPawn::Tick( float DeltaTime )
{
        Super::Tick( DeltaTime );

        float inputYaw = InputComponent->GetAxisValue(TEXT("Yaw"));
}

InputYaw is only one of the three values: 0.0f, -1.0f and 1.0f.
I can see the values I want when I run ShowDebug INPUT from the console. These RAW values represent the analog values of the sticks. But, how can I access those values? The GetAxisValue only returns whole values and I don’t see a method like GetAxisRawValue. I also played around with the deadzones, exponents and scale settings, but nothing really changes the output.

Can someone point me in the right direction or tell me what I am doing wrong?

Hey elquedro-

If you are trying to get the value of the controller’s analog sticks, you may want to take a look at the code for the third person template project. For example, the forward/backward movement axis is bound using InputComponent->BindAxis("MoveForward", this, &ProjectNameCharacter::MoveForward); which will call the ProjectNameCharacter::MoveForward() function any time any button bound to the MoveForward input is pressed.

Cheers

Hello ,

I think I found the problem I am having. I was using the Gamepad Left Thumbstick Up and Gamepad Left Thumbstick Down instead of the Gamepad Left Thumbstick Y-Axis. Stupid mistake.

So, now I am onto the next problem, which is that I am receiving nan values from the Axis.

Do you have a suggestion for that as well?

I believe the issue may be related to the code in the SetupPlayerInputComponent() function. Looking at the code for the third person template character, the SetupPlayerInputComponent() declares the binding as:

InputComponent->BindAxis("MoveForward", this, &AMyProject4Character::MoveForward);
InputComponent->BindAxis("MoveRight", this, &AMyProject4Character::MoveRight);

With "MoveForward" and "MoveRight" being the name of the axis in the project settings while AMyProject4Character::MoveForward and AMyProject4Character::MoveRight are references to the code functions that are called when the input is registered.

Using this setup the code in your Tick function accurately provided the axis value.

I solved the issue by changing the Deadzone to 0.25 to all in-use Axis. I found this value in the FPS example. I did not try hard enough with the deadzone before.

I also tested my original situation (Using GetAxisValue()) and that works as well.

So, if you use a Xbox One controller and you receive NaN values for your input axis, then try changing the Deadzone of the axis to 0.25. You can find these settings in EditProject Settings and then go to Input under Engine.

@ Thanks for helping out!