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.

150 Upvotes

62 comments sorted by

10

u/eedok Dec 16 '13

2

u/drakfyre Expert Dec 16 '13

When did this happen! This looks AWESOME!

I am going to give a shot at integrating it into our Ludum Dare Jam entry, thank you!

5

u/Aggravating-Sink-520 Apr 10 '22

personally love this guy

3

u/drakfyre Expert Apr 10 '22

Awww, thanks! <3

Drop me a line if you ever have any questions.

5

u/GamingStef Indie May 11 '22

This doesn't seem to be correct.

RightStickY isn't the 4th axis, but the 6th, and L2 and R2 are 4th and 5th.

Which honestly does seem weird, isn't the mapping the same for all ps4 controllers? Why would they do this?

1

u/drakfyre Expert May 11 '22

Thanks for the info. I may go in and see what it's doing now, for curiosity's sake. What version of Unity are you running?

Though again, I recommend using the new input system and avoiding this entirely.

→ More replies (1)

3

u/Sennior_Duck Dec 19 '21

Sorry I have a problem because I use the old Input System I couldn't find the "name" for the RightStickPress, PS4

Example: Input.GetKeyDown(KeyCode.RightStickPress)

Please if you could help me that would be great! :)

5

u/drakfyre Expert Dec 19 '21

It isn’t in GetKeyDown, it’s not a key. You need to make the entries in the Axes in the Input settings (this is all still part of the legacy input system) and use GetAxis instead.

4

u/Sennior_Duck Jan 17 '22

Thank you very much for replying😊

→ More replies (2)

5

u/skyline79 Dec 24 '21

Just wanted to say how ridiculous it was expecting OP to respond 8 YEARS after he posted this, and yet he managed it... amazing :-D

3

u/Sennior_Duck Jan 17 '22

Actually, I didn't release it was 8 years ago he created this post, but I'm glad he responded😁

2

u/Rubb3rDucky Hobbyist Apr 03 '14

Interesting. Now I need to figure out how to set up the PS4 controller on pc so I can stop testing with a keyboard

5

u/drakfyre Expert Apr 04 '14

Step 1: Plug in via USB

Step 2: You are done.

You don't even have to restart Unity if it's already running.

4

u/Rubb3rDucky Hobbyist Apr 04 '14

Guess I was thinking it was gonna be a process like the ps3 controller.

2

u/AngusPrime509 Apr 08 '22

Would the xbox controller be the same? just replace the buttons respectively?

1

u/drakfyre Expert Apr 09 '22

I don't think so.

https://answers.unity.com/questions/1350081/xbox-one-controller-mapping-solved.html

Also this may help on future controllers:

https://forum.unity.com/threads/finding-joystick-mapping-inputs-with-unity.204429/

That said if you can move to the new Input system that's a better way to go these days.

2

u/AngusPrime509 Apr 09 '22

Thanks! You rock!

2

u/[deleted] Apr 10 '22

This REALLY helped with my platformer. Thanks a lot!

1

u/drakfyre Expert Apr 10 '22

Is there some game jam or something going on because this post has got a lot of traction recently hahaha!

2

u/[deleted] Apr 16 '22

This is probably the most useful post. It really helped with my game! Thanks! (I think I might have already said that but i dunno.)

1

u/drakfyre Expert Apr 17 '22

Hey, thanks. Where did you hear about this? I keep seeing people show up here in the last week or so after this has been dormant for like 8 years. I'd love to know what caused this sudden "rush" for this information.

3

u/pUbErtYy-_-49 Feb 19 '24

Just want to come in 2 years later to tell you that your post is the 1st result when you search for "unity ps4 controller mapping".

2

u/drakfyre Expert Feb 19 '24

Well I'm honored lol. Still it's funny to me that people even need this now with the new controller stuff; though admittedly it is real easy to use.

3

u/Global_Ad3707 Apr 26 '22

Hey OP, just wanted to say thanks for the post even though I'm only finding it now after 8 years lol

Your post is linked in the iRDS Discord, That's probably where everyone is coming from.

2

u/[deleted] May 01 '22

Left joystick in a ps4 controller is joystick 1 but wich number is the right joystick?

2

u/drakfyre Expert May 01 '22

It's 3rd and 4th axis. The "Joystick #" is for when you have multiple controllers connected, it's not an axis for a stick.

(So they'd both be Joystick 1 for a single-player game.)

2

u/[deleted] May 01 '22

Thanks! Really helped me out, I was trying with every controller number lol

1

u/drakfyre Expert May 01 '22

No problem! :> If you have other questions please ask, I'm pretty familiar with Unity.

→ More replies (1)

2

u/SirHurtzAlot Jun 30 '22

9 years later, and this is still helping! thank you kind sir!

2

u/drakfyre Expert Jun 30 '22

You are very welcome, drop me a line if you ever have any questions on stuff. :>

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 Expert Jul 01 '22

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

2

u/SirHurtzAlot Jul 04 '22

I saw a lot of tutorials for it and I didn't like it.

I prefer having more control over my code and using a UI/editor based control system didn't fit that. I'd much rather spend an entire day writing stuff myself (which I ended up doing tbh XD) than use that.

Although I DID have to use the old control system to map the buttons, it felt much better than using the new system.

→ More replies (1)

2

u/[deleted] Aug 29 '22

Thank you so much for this. It's ridiculous how specific this is yet it's VERY VERY USEFUL. Thanks again.

1

u/drakfyre Expert Aug 29 '22

Hey, no problem, though do make sure everything still works right, some folks said the mappings were different for them.

2

u/[deleted] Aug 30 '22

It worked for me. Thank you.

1

u/drakfyre Expert Aug 30 '22

Interesting..... now I wonder what causes the difference! Hahaha.

2

u/LoquatNew9008 Dec 25 '22

YOu ARE FUCKING HERO THANK TOU

1

u/drakfyre Expert Dec 25 '22

Glad it was helpful. :> Merry Christmas and good luck on your projects!

2

u/BitMillerReddit Jan 29 '23

Thank You for your work, but I have problems implementing it. Lack of information.

I'm thinking in the "old" Input Manager for now.

I take this line forexample: "Square = joystick button 0"

The word "Square", I should write it to the "Name" field. OK.

Where should I write "joystick button 0"? To one of "Negative / Positive / Alt Negative / Alt Positive Button" fields? Because in the rolldown menus "Type / Axis / Joy Num" there aren't an option for "joystick button 0".

Plus (less important): Should I set Snap? And what do you suggest using for "Gravity / Dead / Sensitivity"?

Thank you!

1

u/drakfyre Expert Jan 30 '23

Where should I write "joystick button 0"? To one of "Negative / Positive / Alt Negative / Alt Positive Button" fields?

Yeah, that should be the place to do it.

Because in the rolldown menus "Type / Axis / Joy Num" there aren't an option for "joystick button 0".

You'll want to set Joy Num to "Any" or to a specific number if you have a local multiplayer game.

Should I set Snap? And what do you suggest using for "Gravity / Dead / Sensitivity"?

Snap, Gravity, and Sensitivity ONLY apply when using a digital input for an analog axis. When you press a button, instead of giving you 1.0, it will give you 0.0 on the first frame and then ramp up to 1.0 based on the "Sensitivity". When you release, it will fall back to 0.0 based on the "Gravity". If you set "snap" it will ignore these values and instantly snap to 1.0 and possibly 0.0 too (I'm sure that it snaps to 1.0, I'm not 100% sure it snaps to 0.0).

Dead zone is for analog devices, it sets the minimum input threshold to go above 0.0; I personally err on setting this high by default (usually around .5 or so) because most analog devices will eventually develop stick drift, and this counteracts that.

→ More replies (1)

2

u/Prize_Morning_7781 Nov 26 '23

What about using DPad as buttons?

Which "joystick button" should I use and can I use it at all?

1

u/drakfyre Expert Nov 26 '23

There's no built-in support for accessing the dpad as buttons, you'll have to write your own solution. It's not hard. (Just check if the axis is higher/lower than a certain value for GetButton equivalent. GetButtonDown is a little trickier but you can do this too by tracking a bool to see if the button was down last frame.)

2

u/trenchofkrieger Aug 12 '25

12 years later and this is still helpful for me, thanks!

1

u/drakfyre Expert Aug 17 '25

No problem!

5

u/xniinja Dec 16 '13

Thanks, saved this post. Should come in handy.

1

u/LucanOrion Sep 18 '22

I don't think this is accurate anymore. I'm trying to remap controls for a game and it's just slightly off.

1

u/drakfyre Expert Sep 18 '22

It may depend on factors. Another user just 19 days ago said the mappings were working for them. But I haven't had time to investigate for myself.

This comment has the alternate configuration if you need it: https://www.reddit.com/r/Unity3D/comments/1syswe/ps4_controller_map_for_unity/iefpqmx/

→ More replies (1)

3

u/MaterialExternal7483 Mar 11 '22

Is there a reason the camera is constantly moving down slowly, I tried multiple controllers so it's not stick drift. It just keeps going

Edit: never mind I figured it out, I just increased the dead to 0.01

2

u/[deleted] Oct 17 '22 edited Oct 17 '22

Having an issue with my right stick input. It could 100% be a hardware issue, but I needed to check here anyway. I'm using the right stick for camera movement, but even when centered the stick is reading out 1,1 for x and y, and just causing the character to spin to the right (and up?)

Shouldn't the center of the stick travel be 0,0?

Edit: fixed. I didn't adjust my sensitivity down. Set it to 1 and it fixed the issue.

2

u/suh_dude_crossfire Jun 17 '23

Literally refer back to this even in 2023, goated post. Thanks!

2

u/OrganicBarracuda4348 Feb 15 '26 edited Apr 22 '26

axis 6 for me (right stick y) old PS4 pad

1

u/VastSufficient2830 Jul 19 '24

Electronic map of PS4 handles