Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Found the internet!
r/gamedev
9
Posted by4 years ago
Silver

Mapping an Xbox One Controller in Unity (including alternate mappings for use on Android devices).

Button/Axis NamePositive Button/AxisType
A ButtonJoystick Button 0Key or Mouse Button
B ButtonJoystick Button 1Key or Mouse Button
X ButtonJoystick Button 2Key or Mouse Button
Y ButtonJoystick Button 3Key or Mouse Button
Left BumperJoystick Button 4Key or Mouse Button
Right BumperJoystick Button 5Key or Mouse Button
View ButtonJoystick Button 6 (PC), Joystick Button ??? (Android)Key or Mouse Button
Menu ButtonJoystick Button 7 (PC), Joystick Button 10 (Android)Key or Mouse Button
L-Click ButtonJoystick Button 8Key or Mouse Button
R-Click ButtonJoystick Button 9Key or Mouse Button
Xbox Guide/Home ButtonJoystick Button 12Key or Mouse Button
Bluetooth Sync Button???Key or Mouse Button
Left Analog Stick (Horizontal)X Axis (Horizontal)Joystick Axis
Left Analog Stick (Vertical)Y Axis (Vertical)Joystick Axis
Right Analog Stick (Horizontal)4th Axis (PC), 3rd Axis (Android)Joystick Axis
Right Analog Stick (Vertical)5th Axis (PC), 4th Axis (Android)Joystick Axis
D-Pad (Horizontal)6th Axis (PC), 5th Axis (Android)Joystick Axis
D-Pad (Vertical)7th Axis (PC), 6th Axis (Android)Joystick Axis
Left Trigger9th Axis (PC), 13th Axis (Android)Joystick Axis
Right Trigger10th Axis (PC), 12th Axis (Android)Joystick Axis

Button Settings:

  • Gravity: 1000

  • Dead: 0

  • Sensitivity: 1000

Axis Settings:

  • Gravity: 0

  • Dead: 0.19

  • Sensitivity: 1

NOTE: On a PC, the 3rd Axis is used for the mouse scroll wheel. However, because Android devices are not designed to be used with a mouse, the 3rd Axis on Android devices gets mapped to the horizontal axis on the right analog stick instead. This means that after the inital first two axes, most of the subsequent axis mappings are one number lower on Android than they are on PC. The only exceptions are the left and right triggers, which are mapped to the 13th and 12th axes, respectively.

I have not yet been able to figure out what the button number is for the View button on Android.

3 comments
85% Upvoted
level 1

thank you rhianu! it's surprisingly difficult to find clear tables like this online. i think it's really strange that unity doesn't have presets for controller support built in yet.

i made this class for testing xbox controller inputs that i find useful. it just exposes some bools and floats to the inspector so you can make sure everything is working:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class XboxControllerTest : MonoBehaviour {

public bool aButton;
public bool bButton;
public bool xButton;
public bool yButton;
public bool leftBumper;
public bool rightBumper;
public bool viewButton;
public bool menuButton;
public bool lClickButton;
public bool rClickButton;
public bool xBoxGuideHomeButton;
public float leftAnalogStickHorizontal;
public float rightAnalogStickHorizontal;
public float leftAnalogStickVertical;
public float rightAnalogStickVertical;
public float dPadHorizontal;
public float dPadVertical;
public float leftTrigger;
public float rightTrigger;

void Update ()
{
	aButton = Input.GetButton("A Button");
	bButton = Input.GetButton("B Button");
	xButton = Input.GetButton("X Button");
	yButton = Input.GetButton("Y Button");
	leftBumper = Input.GetButton("Left Bumper");
	rightBumper = Input.GetButton("Right Bumper");
	viewButton = Input.GetButton("View Button");
	menuButton = Input.GetButton("Menu Button");
	lClickButton = Input.GetButton("L-Click Button");
	rClickButton = Input.GetButton("R-Click Button");
	xBoxGuideHomeButton = Input.GetButton("Xbox Guide/Home Button");
	leftAnalogStickHorizontal = Input.GetAxis("Left Analog Stick (Horizontal)");
	rightAnalogStickHorizontal = Input.GetAxis("Right Analog Stick (Horizontal)");
	leftAnalogStickVertical = Input.GetAxis("Left Analog Stick (Vertical)");
	rightAnalogStickVertical = Input.GetAxis("Right Analog Stick (Vertical)");
	dPadHorizontal = Input.GetAxis("D-Pad (Horizontal)");
	dPadVertical = Input.GetAxis("D-Pad (Vertical)");
	leftTrigger = Input.GetAxis("Left Trigger");
	rightTrigger = Input.GetAxis("Right Trigger");
 }
}
1
level 2
Op · 4 yr. ago

Sweet. I just attach it to any game object, right?

1

About Community

All things related to game development, programming, math, art, music, business, and marketing.
714k

game developers

784

Online


Created May 19, 2008
We use cookies on our websites for a number of purposes, including analytics and performance, functionality and advertising. Learn more about Reddit’s use of cookies.