Sign in to follow this  

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

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

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

This topic is 1189 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this