x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.12
Tags:
more ▼

asked Aug 01 '16 at 08:05 AM in C++ Programming

avatar image

elquedro
1 3 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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 Edit -> Project Settings and then go to Input under Engine.

@Doug Thanks for helping out!

more ▼

answered Aug 03 '16 at 09:56 PM

avatar image

elquedro
1 3 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

Doug Wilson

more ▼

answered Aug 01 '16 at 09:26 PM

avatar image elquedro Aug 02 '16 at 08:47 PM

Hello Doug,

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?

avatar image Doug E ♦♦ STAFF Aug 03 '16 at 01:46 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question