-
Notifications
You must be signed in to change notification settings - Fork 15
5. Arcade Input
- Utility Script
- Controls (XBOX... now arcade cab)
- Debug scenes
The static class ArcadeInput.cs is meant to provide you with the necessary code to easily interface with the arcade cabinet controls. It provides both keyboard controls and XBOX Series X|S controller controls for testing purposes.
The arcade cabinet has one (1) 8-way-joystick and two (2) action buttons mapped. While the physical cabinet has more inputs, the mini game is restricting input complexity to achieve overarching design goals.
You can think of the joystick as four separate digital buttons for up, down, left, and right. The joystick can do diagonals of up-left, up-right, down-left, down-right. You can get this input as a Vector2 but note there is not "in-between" these inputs; they are on or off, and in one of those 8 directions.
The two (2) digital buttons are for actions. Consider Action1 the primary action in your game (eg. jump in a platformer, shoot in a shooter, etc), and Action2 as the secondary action.
There are two test scenes in the project to help debug input.
Assets/Scenes/debug-arcade-input.unityAssets/Scenes/debug-input.unity
This scene displays the input mapped through ArcadeInput.cs on screen for both players. This is a good scene to use to check how the keyboard controls and/or XBOX Series X|S controller maps to the input class.
A reminder that you can book out XBOX controllers from Mohawk's Equipment Room, though you must first register and wait for someone to confirm your account creation before booking (one-time setup). https://equipmentroom.mohawkcollege.ca/
This scene displays the input native to Unity's default Input Manager before it is handled by Arcadeinput.cs. If the previous scene is not working, this scene is a good sanity check.
First, you must include the ArcadeInput script on any object in your scene for it to work. You need only one instance, and it can be on any object.
Then, in code, you can access input.
// This assumes the ArcadeInput component is present on a GameObject in the current scene.
public void ExampleFunction()
{
/ BUTTONS, ACTIONS
// Pressed, Released, Up, and Down options for buttons.
bool p1_action1_pressed = ArcadeInput.Player1.Action1.Pressed; // Button was just pressed
bool p1_action1_released = ArcadeInput.Player1.Action1.Released; // Button was just released
bool p1_action2_up = ArcadeInput.Player1.Action2.Up; // Button is up (not held down)
bool p1_action2_down = ArcadeInput.Player1.Action2.Down; // Button is held down
// AXES, PLAYERS
// Note we're now accessing Player2.
float p2_x = ArcadeInput.Player2.AxisX;
float p2_y = ArcadeInput.Player2.AxisY;
Vector2 p2_xy = ArcadeInput.Player2.Joystick8Way;
// PLAYERS VIA ARRAY
// Note there is also an array to get either player by int index.
Vector2 p1_move = ArcadeInput.Players[1].Joystick8Way;
Vector2 p2_move = ArcadeInput.Players[2].Joystick8Way;
// JOYSTICK AS BUTTONS
// Finally, you can get joystick inputs as buttons, too.
bool p1_direction_up = ArcadeInput.Players[1].Up.Held; // Up is being held?
bool p1_direction_down = ArcadeInput.Players[1].Down.Inactive; // Down is not being held?
bool p1_direction_left = ArcadeInput.Players[2].Left.Pressed; // Left was just pressed
bool p1_direction_right = ArcadeInput.Players[2].Right.Released; // Right was just released
}