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? .)

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;

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

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

D-pad Down : -ve 7th Axis

D-pad Left : -ve 6th Axis

D-pad Right : +ve 6th Axis

(copied from http://forum.unity3d.com/viewtopic.php?p=94453)

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.

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; }
	}
}

Converting joyStick Dpad( 6th & 7th Axis) to button.
i referred many communities for this but many of them where incomplete or non detailed.
so here is a simple version that everyone can get it. Thanks to @ CodeMasterMike.
Sorry i was late rpy…!

public class joy_Dpad_2 : MonoBehaviour {

public int countX;
public int countY;

private bool X_isAxisInUse = false;
private bool Y_isAxisInUse = false;

void Update()
{
	if( Input.GetAxisRaw("DpadX") != 0)
	{
		if(X_isAxisInUse == false)
		{
			if(Input.GetAxisRaw("DpadX")==+1)
			{
				countX+=1;
			}
			else if(Input.GetAxisRaw("DpadX")==-1)
			{
				countX-=1;
			}
			X_isAxisInUse = true;
		}
	}
	if( Input.GetAxisRaw("DpadX") == 0)
	{
		X_isAxisInUse = false;
	}    

//----------------------------------------
	if( Input.GetAxisRaw("DpadY") != 0)
	{
		if(Y_isAxisInUse == false)
		{
			if(Input.GetAxisRaw("DpadY")==+1)
			{
				countY+=1;
			}
			else if(Input.GetAxisRaw("DpadY")==-1)
			{
				countY-=1;
			}
			Y_isAxisInUse = true;
		}
	}
	if( Input.GetAxisRaw("DpadY") == 0)
	{
		Y_isAxisInUse = false;
	}    
}

}