3C part 2 – Control
Japan is very cute... but you're here for an update? Briefly: before travelling I added a settings menu to let players customize their input scheme.
The engine supports two types of inputs:
- events : could fire multiple times per frame especially if fps is low (imagine pressing the "open door" button or the "reload weapon" one)
- values : some value usually between -1 and 1, for when it's only a state to be used for the duration of the frame (imagine the "steering" joystick or the "throttle" button)
Those inputs can then be mapped with a lot of freedom: an event could be a button being pressed, a trigger going past a threshold, etc., and a value could be the state of a joystick or a virtual joystick driven by a positive and a negative key.
The game itself has need for 3 types of inputs:
- events (e.g. respawn, change camera)
- binary values (e.g. throttle, brake)
- continuous values (e.g. steering)
So I created 3 variants that support basic mapping types for those 3 types of inputs the game needs:
- events: a key/button being pressed oran axis above/below a threshold, using auto-detection so it's easier for the player
- binary values: similar, except it relies on polling and not keyboard/mouse events
- continuous values: a gamepad joystick/trigger, a virtual axis driven by two buttons, a virtual axis driven by the difference between 2 gamepad axes (so steering can be controlled by 2 triggers, for instance)
And those variants (saved in settings) are then mapped at runtime to input mappings supported by the engine. There is many other combinations that would be possible but I decided to keep it simpler for now so it remains easy for the player. Here it is in action:
bonus: I finally got to confirm my car control works with binary steering (keyboard).
