I’m working on a VR project where I use gloves to control the a standard RigidBodyFPSController. When I make a fist, I want to walk forward. The standard charactercontroller moves on WASD: how could I simulate a W press by holding my glove in a fist?
What I would be looking for is something like
void SimulateW()
{
if (Input.SetKeyDown(KeyCode.W))
{
MoveForward();
}}
Thanks.
Instead of simulating a keypress you want to make your own input commands and simulate those with your various input methods.
Something like…
enum InputCommand { MoveForward, MoveBackward, etc... }
InputCommand command;
void HandleCommand()
{
if (command == InputCommand.MoveForward)
{
MoveForward();
}
}
You can now set the command variable by any means of input. Your code that handles that input doesn’t care how it was set, just that it is set. So you can create a keyboard input handler that sets command to MoveForward when KeyCode.W is pressed. And you can create a VR input handler that sets command to MoveForward when you make a fist. And so on.
Unity provides much of this input virtualization already in the form of Input.GetAxis. You can set up the names and corresponding input values in the input manager. I don’t know if they extend this to support VR commands but if they do that would be a good approach. Otherwise it’s not too troublesome to handle it yourself.