1
\$\begingroup\$

I've looked around and had no luck, so I want to ask here. I'm using an XBOX ONE controller for my game, I've set up the input, however my issue is with the Dpad itself.

Below is an example of how I want to implement the Dpad, but with actions instead of weapons: enter image description here

but the problem is, I can't find any tutorials to explain how to actually go about setting something like this up. Initially, I tried going into the Project Settings, changing the Input but the Dpad is limited to axises and won't actually work as individual buttons.

What would be the best way to get the Dpad to work individually as buttons?

\$\endgroup\$
0
\$\begingroup\$

but the Dpad is limited to axises and won't actually work as individual buttons.

This is by design. If you want to do something specific when a D-pad direction is pressed, you can do so the same way that you would detect if a player had pushed their thumbsticks up, or left, or right, or down.

You need to check what direction, if any, each dpad axis is pointing and then do something.

This unity answers thread is helpful

The parts we specifically care about are these

float x = Input.GetAxis("DPad X");
float y = Input.GetAxis("DPad Y");

IsLeft = false;
IsRight = false;
IsUp = false;
IsDown = false;

//Adjust these numbers to taste
if (x == -1)
    IsLeft = true;
else if (x == 1)
    IsRight = true;

if (y == -1)
    IsDown = true;
else if (y == 1)
    IsUp = true;

The one caveat is I'm not 100% sure if the names of the axes are correct here, you'll have to check your input settings. But there is no "Press dpad button left". You need to check the axes to see if the user pressed it far enough left, right, up or down.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ You probably don't want to compare floats for exact equality without some rounding. Otherwise x = 0.9999f would be considered "not right". Instead, consider using a range, optionally with some hysteresis for stability. \$\endgroup\$ – DMGregory Mar 6 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.