How to map controls for any controller.

Hello,
As the title states i would like to know how to map my games controls to any controller. By this i mean how can i compensate for that fact that on a ps4 controller up and down on the left hand stick is the X Axis while on a xbox controller it is the Y Axis. Is this even possible?

1 Like

I’m not sure about any possible controller out there, but at the very least for PS4 and XB controllers, the default unity input settings should work pretty well. I am not sure what’s causing you to see the X/Y Axis mismatch between the controller types, but that’s not how the unity input is set up by default - on both the PS4 and XB controllers, the button with the “X Axis” label is the left-stick horizontal axis, and the “Y Axis” label is the left-stick vertical axis.

This graphic (courtesy Jimmy Vegas - source http://www.jvunity.weebly.com/uploads/4/7/6/0/47606749/controlmap.png) is useful in knowing the button labels to match up with Inputs. The labels correspond very closely between the two controller types.

Just to ensure this was accurate, I tried plugging both an XB and PS4 controller in and using both on a my project, and both responded identically using the default unity Input setup. Is it possible that your input settings of your project have gotten mangled? You can check this by going Edit > Project Settings > Input in unity. I’ve included an example of what they look like by default, with the horizontal and vertical controller setups expanded for details. I’d double-check your project against that just to make sure it all lines up.

As for other controllers, I’m not sure - I imagine unity’s support varies from controller to controller, I doubt there is one single sure-fire way to support every one. PS4 and XB controllers are going to be the vast majority of your install base. If you’re going for non-standard controllers, you might check the Asset store? I know for instance there is a package that lets you get input from a Wii remote via bluetooth on there - possibly there are others for the controller you’re interested in?

I have an Xbox One controller which seems to have the same mapping as the “Jimmy Vegas” picture above. But the image is not accurate, at least for the PS4. For example, on PS4, X is button 1, not zero, and R2 is 3rd Axis or 7th button. Use this for PS4: Reddit - Dive into anything

However I think the bigger issue is that two controllers with similar physical layouts and shared button index number or axis numbers might have conflicting mappings. “X” is button 1 for a PS4 controller, and “A” is button 0 for an Xbox controller, so if you want a game to have X and A do the same thing (because the user might be playing it through Steam, say, with one of the two controllers, and in terms of physically position on the controller these buttons correspond) how do you do it? With Unity’s input system it doesn’t seem possible, because you’d end up with a configuration where both X and and Square (via PS4 controller, inputs 0 and 1) do the same thing (in game), while also both A and B (on Xbox controller, inputs 0 and 1) also do the same thing.

The mapping of the images given by the user above is accurate if you program for each of those controls, otherwise on Windows at least the one for PS4 is wrong.