How do I get started with controllers? I want to map controls to a 360/PC controller but I don't know where to begin? I'm having no problems with mapping controls to keyboard and mouse, but I don't know how to have Unity recognize my controller to begin with. Any help would be great, thanks in advance.
You should note that if you install the controller while Unity is running, it will not work until you restart the program. (Using model 1403;1086 and Unity 4.0.0f7).
Answer by Novodantis 1
Nov 19, 2009 at 10:42 PM
Unity should recognise it so long as windows does (not sure how well 360 controllers work with Macs). If you plug in your 360 controller (wired works best) and get windows to see it fine under Game Controllers, you should have no problems using it in a Unity Game. Make sure you use Input.GetAxis and Input.GetButton rather than Keys, and check your Project>Input Settings for default button assignments to the joystick.
Edit: Two additional points: although the 360 controller works as-is on Vista and later, you will need to get a driver for XP to see it, much like the PS3 SixAxis does.
The other thing is, I would not recommend getting direct joystick keycodes in Unity; far better to use GetButtonDown("Fire1"), as that will be called if the user pressed left mouse button, left CTRL or Fire 1 on the joystick (by default). The user can also re-map the keys when using GetButton and GetAxis. Have a look at the 3D Platformer tutorial, you should find that works with controllers straight away. Interestingly, though, I found I had to invert the Y axis when using a controller or else the stick forward-back motion was the wrong way around.
@Alexander when using names like "Fire1" instead of keycodes, is it possible to create custom names like "Magic1"?
yea you can name it anyway you want in the inputmanager.
Answer by Brian Kehrer
Nov 22, 2009 at 02:31 AM
If you are using a Mac, or want to package a driver for mac, here is an open source driver.
Mac 360 Controller Driver
Also of note,
Post on buttons mappings for a 360 controller
Answer by Kiyaku
Nov 19, 2009 at 11:51 PM
I tried it with a PS3 controller once.
I had to:
Or you can use a PS3 controller on a Linux
Answer by melgu
Mar 17, 2012 at 12:11 AM
This should help...
Unfortunately this page is at best incomplete. It talks about stuff like X = "joystick button 2". But The input "joystick button 2" does not exist (unless you create it, I guess).
No, joystick button 2 is the proper name for it. You can create an axis in the input manager using that as the button. It works the same as "right ctrl", or "right shift", etc.
Answer by Merrik44
May 12, 2013 at 03:18 PM
I wrote a simple script to get controller input in the same way other keys are accessed. It also works with the web player.
You can download it here:
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
8 People are following this question.
What are all the joystick buttons for an Xbox 360/PC Controller?
My game controller's face buttons and right joystick is the same buttons, how can i separate them individually?
2issues: Xbox Controller axis returns value that's constantly changing and a build problem.
Is there a better way of doing this?
How to fix a game objects that changes its position when viewed in game mode?