Jump to content
  • Advertisement
Sign in to follow this  
funnymango

Unity How to make use of Gamepad controls instead Arrow Keys in Unity?

This topic is 1548 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

Here is a Unity arkanoid tutorial where the paddle is controlled with arrows keys:

 

if (Input.GetKey(KeyCode.LeftArrow))

...
if (Input.GetKey(KeyCode.RightArrow))
...

 

Is it possible to change it so it uses a gamepad?

Thanks!

Share this post


Link to post
Share on other sites
Advertisement

Did you look up your input manager?

Instead of pooling keycode.key, you should have something along the lines of:

Input.GetKey.Up

where Up is a definition in your input manager that refers to the gamepad.

 

If you want to use the pads as progressive input though, you'll need to do a bit more work.

Share this post


Link to post
Share on other sites

If you want to use the pads as progressive input though, you'll need to do a bit more work.

Recommended.

 

It is not particularly hard to set up, so I'll take "a bit more work" as in a single bit, the smallest value.

 

In the Input Manager make an axis, we'll call it "Horizontal".  Map horizontal positive right arrow and an alternate button of "D", with the negative button mapped to left and an alternate button of "A". Then you can create another axis with the same name mapped to a joystick axis.

 

That's it.

 

In fact, that axis is possibly already configured for you depending on how you created your project. Usually it generates the Horizontal and Vertical axis, Fire1, Fire2, Fire3 buttons, among others.

 

 

 

 

When you are done you can read the axis value as a range.

 

int horizontal = Input.GetAxis("Horizontal");

 

which gives a value between -1 and +1.  If you get a -1 you move full speed to the left, +1 is full speed to the right, 0.5 is half speed, or whatever makes sense for your game.

Edited by frob

Share this post


Link to post
Share on other sites

I believe you also have the ability to simulate a 'button press' (boolean-like) interpretation of the input instead of taking the raw input (between -1 and 1 float)
Dont remember how unfortunately.
Frob, do you know the name of that option?
I remember it was in the hour and a half session hosted in Unity tutorials regarding inputs...

Edited by Orymus3

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!