- Home /
Setting multiple jump buttons
I'm working on a project that uses a gamepad. Currently, the left joystick controls movement, the right joystick controls the camera, and the X or A button is jump.
The issue is that I want to set multiple buttons to jump. Ideally, I'd have a clean way to make every button besides the joystick execute a jump.
I have tried Input.GetButtonDown, Input.GetKeyDown, and Input.anyKeyDown and checking the output against my movement keys and executing a jump on a false return, but it doesn't seem to work that way. I can't compare output to KeyCodes because it's a string, and when I try to compare to strings it spits out this error:
UnityException: Input Key named: is unknown
I've also tried adding more keys to my "Jump" input, but it can't seem to handle more than one button at a time.
Answer by dhfijhgky · Jan 15, 2014 at 03:02 AM
I was overthinking it. By just changing this:
if(Input.GetAxis("Jump"))
to this:
if(Input.anyKey)
Any controller button presses are registered and joystick movement is ignored. The only side effect is that it's impossible to move with a keyboard without jumping, but that's fine for what I need. Thanks for the help.
Answer by ccwiegreff · Jan 15, 2014 at 12:07 AM
go to the CharacterMotor or FPSInputController script and change the input button to whatever you desire
Answer by jhart08 · Jan 15, 2014 at 03:20 AM
Go to Edit > Project Settings > Input. Add 2 more inputs, name both "Jump", and set the Positive Button to "joystick button 0" and the other to "joystick button 2" (look here http://wiki.unity3d.com/index.php?title=Xbox360Controller for controller layouts).
You also might want to add a 3rd "Jump" input to assign to the space button or something, at least for the sake of testing. Make sure all are "Key or Mouse Button" types, with Gravity and Sensitivity set to 1000, and Dead set to 0.001.
It can handle multiple inputs for the same virtual button just fine, so most likely the problem has to do with one or more of the above things. Make sure you're referring to the correct layout, since it varies by platform.
Then in Update, you can have
if(Input.GetButtonDown("Jump"))
{
//Jump
}
Your answer
Follow this Question
Related Questions
Getting analog input values from multiple controllers 2 Answers
How do I use controller knob input like mouse position? (New Input System) 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
my ball sometimes jumps higher or sometimes not 2 Answers
Why doesn't this do anything? 1 Answer