Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
3
Question by alexnode · Aug 12, 2010 at 11:47 AM · inputjoystickgamepadxbox360

How to use the XBox 360 Controller D-Pad (PC) ?

Hi all,

After checking the forums i managed to setup an xbox controller for presentations, the only thing i don't understand is the d-pad. How does it work ? i wanted to use it as simple buttons and not axis. Is that possible? I see that the mac driver treat D-pad as buttons is that the case for PC too? . Thanks.

here are the mappings

http://answers.unity3d.com/questions/581/what-are-all-the-joystick-buttons-for-an-xbox-360-pc-controller

EDIT( I think i have to make a script that takes the Axis -1 1 and transform them to boolean buttons, is the dpad the 7th and 6th axis? .)

Comment
Add comment · Show 2
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 Ares · Aug 12, 2010 at 12:29 PM 0
Share

$$anonymous$$y answer isn't formatted well, don't know why it's doing that. The D-pad uses button 2,3,4,5

avatar image alexnode · Aug 12, 2010 at 12:37 PM 1
Share

I think the pc driver doesn't recognises the dpad as buttons but axis. Except if i am missing something really obvious in the input manager. But thanks anyway

6 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by stonstad · Nov 30, 2018 at 03:19 AM

Fun. So the examples above do not compile or they are unfortunately wrong. This is an old thread ... but if you are wanting to treat DPad input as a non-repeating button (e.g. Input.GetButtonDown), here's an approach that is simple and likely the fewest number of operations possible. Make sure to attach this script to a game object.

 using UnityEngine;
 
 public class DPadButtons : MonoBehaviour
 {
     public static bool IsLeft, IsRight, IsUp, IsDown;
     private float _LastX, _LastY;
 
     private void Update()
     {
         float x = Input.GetAxis("DPad X");
         float y = Input.GetAxis("DPad Y");
 
         IsLeft = false;
         IsRight = false;
         IsUp = false;
         IsDown = false;
 
         if (_LastX != x)
         {
             if (x == -1)
                 IsLeft = true;
             else if (x == 1)
                 IsRight = true;
         }
 
         if (_LastY != y)
         {
             if (y == -1)
                 IsDown = true;
             else if (y == 1)
                 IsUp = true;
         }
 
         _LastX = x;
         _LastY = y;
     }
 }

alt text

Invocation

 if (DPadButtons.IsLeft) ...  // executes once and only once per button press


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 THAXTERIA · Mar 11, 2020 at 05:31 PM 0
Share

Very nice, thanks!

avatar image
1

Answer by gglobensky · Oct 10, 2018 at 07:13 AM

bool isRight = (Input.GetAxis ("DPadX") < -0.1f) ? true : false;

bool isLeft = (Input.GetAxis ("DPadX") > 0.1f) ? true : false;

bool isDown = (Input.GetAxis ("DPadY") < -0.1f) ? true : false;

bool isUp = (Input.GetAxis ("DPadY") > 0.1f) ? true : false;

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 Ares · Aug 12, 2010 at 12:25 PM

Yeah, the D-pad works.

Button 0 - nothing Button 1 - nothing Button 2 - DPad Up Button 3 - DPad Down Button 4 - DPad Left Button 5 - DPad Right Button 6 - Start Button 7 - Back Button 8 - Left Analog Stick Press Button 9 - Right Analog Stick Press Button 10 - Left Shoulder Button Button 11 - Right Shoulder Button Button 12 - XBox Button Button 13 - A Button 14 - B Button 15 - X Button 16 - Y Button 17 - nothing Button 18 - nothing Button 19 - nothing

Analog Stick Axes Same as drJones

5th Axis - Left Trigger 6th Axis - Right Trigger

I got this from here: http://forum.unity3d.com/viewtopic.php?t=5563&highlight=360+controller

It's possible to have more than one controller running at a time, I don't have that info on me right now.

Thanks, Ares

::edit:: I don't know why the formatting it jacked up.

alexnode pointed out I listed the layout for a MAC. PC treats the D-pad differently.
D-pad Up : +ve 7th Axis \n
D-pad Down : -ve 7th Axis \n
D-pad Left : -ve 6th Axis \n
D-pad Right : +ve 6th Axis \n
(copied from http://forum.unity3d.com/viewtopic.php?p=94453)

Comment
Add comment · Show 4 · 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 alexnode · Aug 12, 2010 at 12:34 PM 0
Share

no this is for mac configuration, with the custom drivers. For PC is different A Button joystick button 0

B Button joystick button 1

X Button joystick button 2

Y Button joystick button 3

L Button joystick button 4

R Button joystick button 5

Back joystick button 6

Start joystick button 7

Left Analog pressed joystick button 8

Right Analog pressed joystick button 9

Left Analog X Axis Joystick Axis, X Axis

Left Analog Y Axis Joystick Axis, Y Axis

Right Analog X Axis Joystick Axis, 4th Axis

Right Analog Y Axis Joystick Axis, 5th Axis

avatar image Ares · Aug 12, 2010 at 12:40 PM 0
Share

Yeah, I just saw that. I'm editting my answer.

avatar image alexnode · Aug 12, 2010 at 12:53 PM 0
Share

Thanks a lot Ares, but still i don't understand how to map them as buttons. What +ve means?

avatar image Jean-Fabre · Oct 27, 2010 at 05:27 AM 0
Share

+ve -> positive -ve -> negative :)

avatar image
0

Answer by mptp · Oct 16, 2014 at 05:15 AM

Since I just found this page trying to do it myself, and nobody had an answer, I thought I'd post what I just came up with to achieve the result the OP was asking about (that is, using the DPad buttons as buttons rather than axes)

You need to do it yourself, unfortunately. Luckily, it's not too hard. Something like this works fine:

 using UnityEngine;
 using System.Collections;
 
 public class DPadButtons : MonoBehaviour {
   public static bool up;
   public static bool down;
   public static bool left;
   public static bool right;
 
   float lastX;
   float lastY;
 
   public DPadButtons() {
     up = down = left = right = false;
     lastX = Input.GetAxis("DPadX");
     lastY = Input.GetAxis("DpadY");
   }
 
   void Update() {
     if(Input.GetAxis ("DPadX") == 1 && lastDpadX != 1) { right = true; } else { right = false; }
     if(Input.GetAxis ("DPadX") == -1 && lastDpadX != -1) { left = true; } else { left = false; }
     if(Input.GetAxis ("DPadY") == 1 && lastDpadY != 1) { up = true; } else { up = false; }
     if(Input.GetAxis ("DPadY") == -1 && lastDpadY != -1) { down = true; } else { down = false; }
   }
 }

Then, in any script, you can do something like

 if(DPadButtons.up) {
   //some code to execute when the up button is pushed
 }


I'm sure you could extend Unity's Input class, but I don't know how to do that, and this works find for me right now.

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 mecha-box · Jan 21, 2015 at 12:20 AM 0
Share

Thanks!! But I got some errors while compiling. I would like to put what worked for me using your work.

avatar image
0

Answer by mecha-box · Jan 21, 2015 at 01:57 AM

 using UnityEngine;
 using System.Collections;
 
 /// <summary> This class maps the DPad axis to buttons. </summary>
 public class DPadButtons : MonoBehaviour
 {
     public static bool up;
     public static bool down;
     public static bool left;
     public static bool right;
 
     private float lastX, lastY;
 
     void Start ()
     {
         up = down = left = right = false;
         lastX =    lastY = 0;
     }
 
     void Update()
     {
         float lastDpadX = lastX;
         float lastDpadY = lastY;
 
         if (Helpers.IsAxisActive (AxisName.DPad_Horizontal))
         {
             float DPadX = Input.GetAxis (AxisName.DPad_Horizontal);
 
             if (DPadX == 1 && lastDpadX != 1)   { right = true; } else { right = false; }
             if (DPadX == -1 && lastDpadX != -1) { left = true;  } else { left = false;  }
 
             lastX = DPadX;
         }
         else { lastX = 0; }
 
         if (Helpers.IsAxisActive (AxisName.DPad_Vertical))
         {
             float DPadY = Input.GetAxis (AxisName.DPad_Vertical);
             if (DPadY == 1 && lastDpadY != 1)   { up = true;   } else { up = false;   }
             if (DPadY == -1 && lastDpadY != -1) { down = true; } else { down = false; }
 
             lastY = DPadY;
         }
         else { lastY = 0; }
     }
 }

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 Kerihobo · Aug 07, 2015 at 09:26 PM 0
Share

Where is "Helpers" and AxisName declared in the above script?

  • 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

8 People are following this question.

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

Related Questions

Getting ScrollWheel/Joystick Direction w/ InputSystem 0 Answers

Rotation of a object depending on where the joystick is facing 1 Answer

Keyboard/Joystick Inputs Do Not Work until Mouse Clicked 0 Answers

Finding the right joystick for aiming/shooting 1 Answer

Gamepad input, axis OR button 0 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