Reputation: 1216
How to allow both keyboard and joystick controller as input in a same scene. and yes, based on priority the other input should get locked.
Upvotes: 1
Views: 3105
Reputation: 1216
I found an answer here
https://www.youtube.com/watch?v=NYZoLOpYp2k
Video shows implementing an additional layer(Inputmanager) and handles the both.
EDIT: Or more simple one is keep the same name for both Joystick and Keyboard. for example, "Horizontal" this input would be created by default for both joystick and keyboard. so basically no need additional code to allow both controls.
Upvotes: 0
Reputation: 301
By default, your project should be able to detect both keyboard and joystick input. See here and here for more info.
As for locking out one or the other, you can use the answer provided here as a starting point, and then block the input not being used.
Ideally, you would want some way of switching between the two, like using the first command from the locked controller to unlock it and then handle input normally. Some games don't block, but rather let the user switch seamlessly between input types and update the UI accordingly. In the end it all depends on your game and what works best for you.
Upvotes: 1