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.

62 comments · 99% upvoted · other discussions

comments

eedok
drakfyre [OP]

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!

xniinja

Thanks, saved this post. Should come in handy.

Aggravating-Sink-520

personally love this guy

drakfyre [OP]

Awww, thanks! <3

Drop me a line if you ever have any questions.

GamingStef

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?

drakfyre [OP]

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.

Upstairs_Day3483

Thanks! I have had many hours spent trying to find why controllers sticks dont work. Finally an answer!

Sennior_Duck

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! :)

drakfyre [OP]

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.

Sennior_Duck

Thank you very much for replying😊

Square-Training-4979

Hey, i need your help !

Sennior_Duck

sorry for replying so late😭

skyline79

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

Sennior_Duck

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

MaterialExternal7483

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

Rubb3rDucky

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

drakfyre [OP]

Step 1: Plug in via USB

Step 2: You are done.

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

Rubb3rDucky

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

AngusPrime509

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

drakfyre [OP]

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.

AngusPrime509

Thanks! You rock!

[deleted]

This REALLY helped with my platformer. Thanks a lot!

drakfyre [OP]

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

[deleted]

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

drakfyre [OP]

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.

Global_Ad3707

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.

pUbErtYy-_-49

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".

drakfyre [OP]

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.

[deleted]

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

drakfyre [OP]

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

[deleted]

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

drakfyre [OP]

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

[deleted]

I just tried it and it still doesnt wor, the y axis is 3rd for me and i havent figured the x, i dont know if it has something to do with my camera script, it might be wrong

SirHurtzAlot

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

drakfyre [OP]

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

SirHurtzAlot

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

SirHurtzAlot

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

drakfyre [OP]

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

SirHurtzAlot

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.

drakfyre [OP]

I guess I should make a tutorial on how to use it programmatically; it's far more powerful in script than the old system, and has no place where you are required to use UI; all operations, including initial mapping (and later remapping) can be done in C# (the editor is quite good though). Plus it has a lot of nice things: action based organization, input passthrough/stoppage for different input modes (if you get in a car you can have a completely different input set, when you pull up a menu again, new input set, so you don't even have to mask inputs based on state; just switch action maps.)

The old system is great for prototyping speed (I usually have both enabled) but it's not as good a base to make a new input system on but hey, if you like what you've got better, I'm not about to tell you to stop. :>

(I do wish that there was a full input layer system with a priority though, so you can have controls be "caught" by a layer above so they don't pass through to other action maps, and still have fall through where it's appropriate, but switching maps can accomplish much of the utility this provides.)

[deleted]

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

drakfyre [OP]

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

[deleted]

It worked for me. Thank you.

drakfyre [OP]

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

[deleted]

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.

LoquatNew9008

YOu ARE FUCKING HERO THANK TOU

drakfyre [OP]

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

BitMillerReddit

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!

drakfyre [OP]

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.

tr0picana

I'm having trouble getting buttons working on Android. In the editor I have every button, trigger, and joystick working as expected but on Android only the joysticks and triggers works. Any ideas on what I could be overlooking?

suh_dude_crossfire

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

Prize_Morning_7781

What about using DPad as buttons?

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

drakfyre [OP]

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

trenchofkrieger

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

drakfyre [OP]

No problem!

OrganicBarracuda4348

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

VastSufficient2830

Electronic map of PS4 handles

LucanOrion

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

drakfyre [OP]

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/

LucanOrion

Yeah, I always seem to run into things not being exactly how it is for everyone else. :)

I play a game called Elite Dangerous on ps4. I'm trying to set up my ps4 controller to play the game on PC and I want it match the ps4 configuration. Below is what the buttons were showing for me.

Buttons

Square = joystick button 1

X = joystick button 2

Circle = joystick button 3

Triangle= joystick button 4

L1 = joystick button 5

R1 = joystick button 6

L2 = joystick button 7

R2 = joystick button 8

Share = joystick button 9

Options = joystick button 10

L3 = joystick button 11

R3 = joystick button 12

PS = joystick button 13

PadPress= joystick button 14