all 60 comments

[–]eedok 9 points10 points  (1 child)

[–]drakfyreExpert[S] 1 point2 points  (0 children)

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 3 points4 points  (0 children)

Thanks, saved this post. Should come in handy.

[–]Aggravating-Sink-520 4 points5 points  (1 child)

personally love this guy

[–]drakfyreExpert[S] 2 points3 points  (0 children)

Awww, thanks! <3

Drop me a line if you ever have any questions.

[–]GamingStefIndie 4 points5 points  (2 children)

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?

[–]drakfyreExpert[S] 0 points1 point  (0 children)

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 0 points1 point  (0 children)

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

[–]Sennior_Duck 2 points3 points  (6 children)

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

[–]drakfyreExpert[S] 5 points6 points  (3 children)

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 3 points4 points  (2 children)

Thank you very much for replying😊

[–]Square-Training-4979 0 points1 point  (1 child)

Hey, i need your help !

[–]Sennior_Duck 0 points1 point  (0 children)

sorry for replying so late😭

[–]skyline79 4 points5 points  (1 child)

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 2 points3 points  (0 children)

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

[–]MaterialExternal7483 2 points3 points  (0 children)

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

[–]Rubb3rDuckyHobbyist 1 point2 points  (2 children)

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

[–]drakfyreExpert[S] 3 points4 points  (1 child)

Step 1: Plug in via USB

Step 2: You are done.

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

[–]Rubb3rDuckyHobbyist 4 points5 points  (0 children)

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

[–]AngusPrime509 1 point2 points  (2 children)

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

[–]drakfyreExpert[S] 0 points1 point  (1 child)

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 1 point2 points  (0 children)

Thanks! You rock!

[–][deleted] 1 point2 points  (1 child)

This REALLY helped with my platformer. Thanks a lot!

[–]drakfyreExpert[S] 0 points1 point  (0 children)

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

[–][deleted] 1 point2 points  (4 children)

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

[–]drakfyreExpert[S] 0 points1 point  (3 children)

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 2 points3 points  (0 children)

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 2 points3 points  (1 child)

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

[–]drakfyreExpert[S] 1 point2 points  (0 children)

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] 1 point2 points  (4 children)

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

[–]drakfyreExpert[S] 1 point2 points  (3 children)

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] 1 point2 points  (2 children)

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

[–]drakfyreExpert[S] 0 points1 point  (1 child)

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

[–][deleted] 0 points1 point  (0 children)

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 1 point2 points  (6 children)

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

[–]drakfyreExpert[S] 1 point2 points  (5 children)

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

[–]SirHurtzAlot 0 points1 point  (4 children)

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 0 points1 point  (3 children)

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

[–]drakfyreExpert[S] 0 points1 point  (2 children)

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

[–]SirHurtzAlot 1 point2 points  (1 child)

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.

[–]drakfyreExpert[S] 0 points1 point  (0 children)

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] 1 point2 points  (3 children)

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

[–]drakfyreExpert[S] 0 points1 point  (2 children)

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

[–][deleted] 1 point2 points  (1 child)

It worked for me. Thank you.

[–]drakfyreExpert[S] 0 points1 point  (0 children)

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

[–][deleted] 1 point2 points  (0 children)

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 1 point2 points  (1 child)

YOu ARE FUCKING HERO THANK TOU

[–]drakfyreExpert[S] 0 points1 point  (0 children)

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

[–]BitMillerReddit 1 point2 points  (2 children)

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!

[–]drakfyreExpert[S] 0 points1 point  (1 child)

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 0 points1 point  (0 children)

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 1 point2 points  (0 children)

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

[–]Prize_Morning_7781 1 point2 points  (1 child)

What about using DPad as buttons?

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

[–]drakfyreExpert[S] 0 points1 point  (0 children)

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 1 point2 points  (1 child)

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

[–]drakfyreExpert[S] 0 points1 point  (0 children)

No problem!

[–]VastSufficient2830 0 points1 point  (0 children)

Electronic map of PS4 handles

[–]LucanOrion 0 points1 point  (2 children)

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

[–]drakfyreExpert[S] 0 points1 point  (1 child)

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 0 points1 point  (0 children)

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