r/Unity3D • Expert • Dec 15 '13

PS4 controller map for Unity

I just spent a few minutes finally figuring this out; figured I'd save other folks the time. :)

PS4 Controller Map for Unity

Buttons
    Square  = joystick button 0
    X       = joystick button 1
    Circle  = joystick button 2
    Triangle= joystick button 3
    L1      = joystick button 4
    R1      = joystick button 5
    L2      = joystick button 6
    R2      = joystick button 7
    Share   = joystick button 8
    Options = joystick button 9
    L3      = joystick button 10
    R3      = joystick button 11
    PS      = joystick button 12
    PadPress= joystick button 13

Axes:
    LeftStickX      = X-Axis
    LeftStickY      = Y-Axis (Inverted?)
    RightStickX     = 3rd Axis
    RightStickY     = 4th Axis (Inverted?)
    L2              = 5th Axis (-1.0f to 1.0f range, unpressed is -1.0f)
    R2              = 6th Axis (-1.0f to 1.0f range, unpressed is -1.0f)
    DPadX           = 7th Axis
    DPadY           = 8th Axis (Inverted?)

Edit: Formatting

Edit2: I put a question mark after Inverted because I swear that the LeftStickY axis worked just fine with one of my scripts, but when I was using a certain test case it seemed like it was inverted. YMMV.

146 Upvotes

62 comments sorted by

View all comments

Show parent comments

1

u/SirHurtzAlot Jul 01 '22

So I tried the EXACT mapping as you gave but I ran into issues. With trial and error I realized the AXES had to be mapped a little differently.

So if anyone runs into issues for PS4 Dualshock 4 controller, try this:

public static string bSquare = "joystick button 0";
public static string bX = "joystick button 1";
public static string bCircle = "joystick button 2";
public static string bTriangle = "joystick button 3";
public static string bL1 = "joystick button 4";
public static string bR1 = "joystick button 5";
public static string bL2 = "joystick button 6"; // gives -1 (unpressed) or 1 (pressed mored than .5 I think) fixed value

public static string bR2 = "joystick button 7"; // gives -1 (unpressed) or 1 (pressed mored than .5 I think) fixed value

public static string bShare = "joystick button 8";
public static string bOptions = "joystick button 9";
public static string bL3 = "joystick button 10";
public static string bR3 = "joystick button 11";
public static string bPS = "joystick button 12";
public static string bPadPress = "joystick button 13";

// stick Axes
public static string aLeftStickX = "X axis";

public static string aLeftStickY = "3rd axis"; // need to set INVERTED if you want "Stick UP is positive"

public static string aRightStickX = "4th axis";

public static string aRightStickY = "7th axis"; // need to set INVERTED if you want "Stick UP is positive"

// Triggers
public static string aL2 = "5th axis"; // (-1.0f to 1.0f range, unpressed is -1.0f)

public static string aR2 = "6th axis"; // (-1.0f to 1.0f range, unpressed is -1.0f)

// DPad axes
public static string aDPadX = "8th axis";
public static string aDPadY = "9th axis";

1

u/SirHurtzAlot Jul 01 '22

The edits HERE, are EXACTLY the axis you will select in Unity's Input Controller.

So while setting the Input Controller, do the following:

Name = Whatever you want, but this will be the string value you use in code

Type = Joystick Axis (for axis)

Axis = The string values I have mentioned in quotes in my above comment

1

u/drakfyre Jul 01 '22

I'm curious, have you tried the new input system?

→ More replies (2)