Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by vexe · Dec 09, 2015 at 08:19 PM · inputjoystickgetaxiscontrollersgetbutton

Get DPad input value via GetButton instead of GetAxis?

Greetings,

I have this generic USB controller. I'm trying to detect its DPad (or analog stick) input values.

Using Input.GetAxis("Horizontal") and Input.GetAxis("Vertical") does work (assuming that I set the joystick axis to X for horizontal, and Y for vertical)

I don't want to deal with GetAxis. Is there anyway I could get the values via Input.GetButton? The only reserved button names I know for joystick in Unity are joystick button N where N could be 0, 1, 2, 3, etc. Is there something like a dpad button 0?

Any help is appreciated, thanks.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image currobot · Jan 18, 2016 at 09:06 AM 0
Share

I have the same question :_(

7 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by maggat · Jul 26, 2019 at 11:29 PM

Another solution to this, a bit clunky but it works.

 public class Dpad : Monobehaviour {
 
     private float dpadX;
     private float dpadY;
     private bool leftDpadPressed;
     private bool rightDpadPressed;
     private bool upDpadPressed;
     private bool downDpadPressed;
     private bool currentlyReleased;
 
 private void Start(){
  currentlyReleased = true;    
  }
 
  private void Update()
     {
         dpadX = Input.GetAxis("Dpad X");
         dpadY = Input.GetAxis("Dpad Y");
         
 
 
         if (dpadX == -1)
         {
             leftDpadPressed = true;
             if(leftDpadPressed && currentlyReleased)
             {
                 //Fire events
                
                 print("LEFT");
             }
 
             currentlyReleased = false;
         }
         if(dpadX == 1)
         {
             rightDpadPressed = true;
             if(rightDpadPressed && currentlyReleased)
             {
                 //Fire events
                 
                 print("RIGHT");
             }
             currentlyReleased = false;
         }
         if (dpadY == -1)
         {
             downDpadPressed = true;
             if (downDpadPressed && currentlyReleased)
             {
                 //Fire events
                
                 print("DOWN");
             }
             currentlyReleased = false;
         }
         if (dpadY == 1)
         {
             upDpadPressed = true;
             if (upDpadPressed && currentlyReleased)
             {
                 //Fire events
               
                 print("UP");
             }
             currentlyReleased = false;
         }
         if (dpadY == 0 && dpadX == 0)
         {
             upDpadPressed = false;
             downDpadPressed = false;
             leftDpadPressed = false;
             rightDpadPressed = false;
             currentlyReleased = true;
         }
 
     }
 
 
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vinchuca · Feb 07, 2021 at 10:40 PM 0
Share

Thankyou for this, it work just like i need. The only thing i had to do is configure the axis in the input manager.

The Vertical axis: Type: Joystick Axis. Axis: 7th Axis (Joysticks). Joynum: Get Motion from all Joysticks. The Horizontal axis: Type: Joystick Axis. Axis: 8th Axis (Joysticks). Joynum: Get Motion from all Joysticks.

avatar image
0

Answer by EyePD · Aug 24, 2017 at 02:42 PM

From what I've been reading it seems that Unity does not allow you to read the D-Pad as buttons on Windows (although you can on Mac & Linux). This is really unfortunate because it makes it much harder than it should be to read discrete events from these buttons but I found this other answer which has some (rather clunky) solutions.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by joshuaflash · Aug 24, 2017 at 03:29 PM

I haven't tested it, but using Input.GetAxisRaw might go a long way in getting the behaviour you desire. It doesn't apply smoothing so hitting the D-Pad left (for example) should return -1 immediately.
So something like

 bool GetDPadButton(string button)
 {
     if (button == "right") return Input.GetAxisRaw("DPadX") == 1;
     if (button == "down") return Input.GetAxisRaw("DPadY") == -1;
     if (button == "left") return Input.GetAxisRaw("DPadX") == -1;
     if (button == "up") return Input.GetAxisRaw("DPadY") == 1;
 }

could work if the Input settings are properly set up. However, I'm not sure what values are returned when two D Pad buttons are pressed or if there are other cases where one of the axis would return a value between 0 and 1.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by satolas · Feb 14, 2018 at 12:21 AM

DPad X or Y are triggering endless events when they'll rich the value of 1 or -1.

The Input.GetButtonDown/GetButtonDown are giving just one state wich let us to increment a value one by one for exemple. Like a Toggle basically.

I was trying some solutions but no solution is working.
Maybe someone will find a solution for that.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image satolas · Feb 14, 2018 at 12:38 AM 0
Share

$$anonymous$$aybe there : https://forum.unity.com/threads/c-xbox-one-controller-d-pad-for-pc-work-like-a-button-getbuttondown-solved.481405/

avatar image
0

Answer by wallmat · Nov 08, 2018 at 05:43 PM

If anyone is still running into this issue one option is to save the previous state of the axis, and if its the same ignore it. this will allow you to only act on each button press.

         var _dir = CrossPlatformInputManager.GetAxis("DPadUpDown");
         if(_dir == LastButtonState)
             return;

         //if its diff then update our last state save that
         LastButtonState = _dir;

         if(_dir > 0)
             //do something awesome
         else if(_dir < 0)
             //Do something awesome in a diff direction
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

42 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

joystick movement 2 Answers

Input.GetAxis returning nonsensical values for HID Sensor/GameController 0 Answers

Joystick input Problem 3 Answers

Why does holding down any button cause ~20-30 FPS loss? 1 Answer

How can I control cursor with joystick 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges