Jump to content
  • Advertisement
Sign in to follow this  

unity3d:how to control a 360 gamepad

This topic is 2302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am a beginner learning unity.

i just finished chapter 6 of "Unity 3 Game Development Hotshot." and i just got a 360 gamepad controller. in the book, the player can aims and then shoot a rocket launcher. i found out which joystick to use and pressed 'A' to fire. but how to program so that i don't have to press 'E' on my keyboard to aim?

also, i still have to use my mouse to control the crosshair. can i use one of joystick on my controller? how do i program unity to map the joystick on my controller? i looked at mouseLook_JS.js, and have no idea how to insert codes to get the input from one of my joystick on the controller. by default, i can move the player, forward/backward/left and right and i can fire while holding 'E' key of my keyboard.

i also dont understand what is Dpad and 5th or 6th Axis?

is there a way to read the inputs in the controller and print out the codes in unity?

any help will be appreciated. Edited by nickme

Share this post

Link to post
Share on other sites

i finally realized that i have to setup the input manager. but in my mouseLook_JS.js, how do i know which input to update transform.localEulerAngles? in my input manager, i added 2 more elements, Mouse1 X and Mouse1 Y. and have their types set to Joystick axis. and their Axis set to 6th Axis and 7th Axis. but how do i know which input to assign to localEulerAngles?

Share this post

Link to post
Share on other sites
The 6th and 7th axes doesn't exist on a 360 gamepad. It has 6 axes numbered from 0 (ie 0 to 5, not 1 to 6)

DPad is literally the direction pad, they are not recognised as actual buttons and are instead classed as a POV hat (which unity calls a DPad, makes more sense on xbox to call it that anyway).
The 5th and 6th axes are the triggers, they aren't digital 1 or 0 input so are read as a full joystick axis.

I think the axes in order are:
0-Left thumbstick X
1-Left thumbstick Y
2-Right thumbstick X
3-Right thumbstick Y
4-Left trigger
5-Right trigger

The X and Y's may be the wrong way round, I think it is read X first though. If unity does infact recognise them as axes numbered 1 to 6 then simply add one the the numbers I've given. If it still insists that there is a 6th axis (or 7th in the event it does number from one) then that one might be a little more complex. Instead of reading each trigger individually it might be outputting the following:

-left_trigger + right_trigger

Not so complex but assuming trigger output is a number between 0 and 1 instead of getting a number for each individual trigger you may be getting a number between -1 and 1 thats sort of a net force across both triggers (this can be useful for a few things occasionally).

Handling input of gamepad buttons is often very similar to a keyboard. Handing the axes can be more difficult though and is also very different to handling a mouse for mouse input. I think the unity website actually has tutorials dedicated to handling gamepad input rather than keyboard, that might give better information than I can (I've only used the 360 pad in XNA, I've never used unity)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!