Input
Overview
Unity
On the Unity side, the Arcade Racing Sample uses simple polling via the old Unity input system. The implementation can be found in GameplayInput.cs.
Quantum
Input Struct
The Quantum input struct is extremely compact and only contains one byte and one signed byte:
- Byte
Flagsare used for a compressed representation of button actions (accelerate, decelerate, nitro, horn, hand brake); and, - SByte
Steeringis used for an analog representation of steering. Unity’s horizontal input axis float (-1 to 1) mapped to sbyte (-127 to 127);
Simulation
In the simulation, the input is tied to InputDesires to provide a single entry point for input generated by Players and AI alike.
- Input is processed using the helper struct
InputDesires(defined inPlayer.InputDesires.cs) in theVehicleandSteeringcomponents. InputDesiresare filled in by either:- a player’s input polled from Unity (see the
Player.Updatemethod); or, - AI input (see
AI.Updatemethod). The AI generates input using theAIHandlingasset which can be easily swapped to further alter the AI's behavior.
- a player’s input polled from Unity (see the