Control Schemes
Cub3D supports three input methods that can be used simultaneously:Keyboard
WASD movement + Arrow keys for looking
Mouse
Mouse look with FPS-style camera control
Gamepad
Full controller support (Xbox, PlayStation, etc.)
Keyboard Controls
Movement
| Key | Action |
|---|---|
W | Move forward |
S | Move backward |
A | Strafe left |
D | Strafe right |
Left Shift | Sprint (increases movement speed) |
Default walk speed: 4.0 units/sec
Sprint speed: 6.0 units/sec
Sprint speed: 6.0 units/sec
Camera Control
| Key | Action |
|---|---|
Left Arrow | Look left |
Right Arrow | Look right |
M | Toggle mouse look on/off |
Keyboard look velocity: 180°/sec
Mouse look velocity: 20.0 (sensitivity multiplier)
Mouse look velocity: 20.0 (sensitivity multiplier)
Actions
| Key | Action |
|---|---|
E | Interact / Open doors |
Space | Use equipped item / Fire weapon |
Q | Drop current item |
R | Cycle inventory (next item) |
Mouse Wheel
When mouse look is enabled:| Input | Action |
|---|---|
| Mouse Wheel Up | Cycle inventory forward |
| Mouse Wheel Down | Cycle inventory backward |
HUD & Debug
| Key | Action |
|---|---|
F1 | Toggle fullscreen |
F2 | Toggle stats HUD |
F3 | Toggle debug info (FPS, coordinates) |
F4 | Toggle minimap |
F5 | Toggle action prompts |
F6 | Toggle entire HUD |
F7 | Reload/detect gamepads |
Minimap Controls
| Key | Action |
|---|---|
8 | Zoom out minimap |
9 | Reset minimap zoom (5.0x) |
0 | Zoom in minimap |
Each zoom level changes by a factor of 1.2x.
Multiplayer
| Key | Action |
|---|---|
P | Activate additional player |
O | Deactivate a player |
Supports up to 4 simultaneous players (split-screen).
System
| Key | Action |
|---|---|
ESC | Return to hub map (maps/hub.cub) |
K | Toggle keyboard-only mode (disables mouse/gamepad) |
Cheat Codes
| Key | Effect |
|---|---|
I | Toggle invincibility + restore health |
B | Toggle noclip (walk through walls) |
The
cheating flag is set when invincibility or noclip is active.Mouse Controls
Mouse Look
Camera movement
Move the mouse left/right to rotate the camera.The cursor is automatically centered, and movement delta is calculated:
Mouse Deadzone
Movements within 10 pixels of center are scaled down to reduce jitter.Gamepad Controls
Supported Controllers
Xbox
Xbox One, Series X/S, 360
PlayStation
DualShock 4, DualSense
Generic
Any SDL2-compatible gamepad
Button Mapping
- Xbox Layout
- PlayStation Layout
| Button | Action |
|---|---|
| Left Stick | Move (forward/back/strafe) |
| Right Stick | Look (rotate camera) |
| LT (L2) | Sprint (when > 80% pressed) |
| RT (R2) | Use item / Fire weapon (when > 80% pressed) |
| LB (L1) | Not mapped |
| RB (R1) | Cycle inventory |
| A (Cross) | Not mapped |
| B (Circle) | Drop item |
| X (Square) | Interact / Open doors |
| Y (Triangle) | Not mapped |
| Menu/Start | Activate (keyboard-only override) |
| View/Back | Not mapped |
Analog Stick Behavior
Left Stick (Movement)
The stick is divided into directional zones:The center deadzone (0.3 to 0.7) prevents stick drift.
Right Stick (Camera)
Same zone mapping for camera rotation:- X < 0.3: Look left
- X > 0.7: Look right
- Center (0.3-0.7): No rotation
Trigger Sensitivity
Controller Deadzone
Raw analog values are filtered:Gamepad Detection
Advanced Configuration
Controller Implementation
The player controller is defined insrc/utils/entities/controller/player/player2.c:player2.c:
Custom Key Bindings
To modify key bindings, editsrc/utils/entities/controller/player/player2.c:player2.c:
Available Key Constants
Keyboard (FTM_KEY_*)
Keyboard (FTM_KEY_*)
FTM_KEY_W,FTM_KEY_A,FTM_KEY_S,FTM_KEY_DFTM_KEY_SPACE,FTM_KEY_LSHIFT,FTM_KEY_ESCFTM_KEY_E,FTM_KEY_Q,FTM_KEY_RFTM_KEY_LEFT,FTM_KEY_RIGHT,FTM_KEY_UP,FTM_KEY_DOWNFTM_KEY_F1throughFTM_KEY_F12FTM_KEY_0throughFTM_KEY_9FTM_KEY_M,FTM_KEY_K,FTM_KEY_P,FTM_KEY_OFTM_KEY_I,FTM_KEY_B
Gamepad Buttons (FTM_GAMEPAD_*)
Gamepad Buttons (FTM_GAMEPAD_*)
Gamepad Axes (FTM_GAMEPAD_*)
Gamepad Axes (FTM_GAMEPAD_*)
FTM_GAMEPAD_LSTICK(Left analog stick)FTM_GAMEPAD_RSTICK(Right analog stick)
Player Configuration Constants
Defined inheaders/cub3d.h:cub3d.h:
Control Flow
The control system processes input through these layers:Controller Event Handler
ftm_controller_event_handler() processes gamepad input in src/ft_mlx_utils/controllers/controllers2.c:controllers2.cTroubleshooting
Gamepad not detected
Gamepad not detected
- Press F7 to reload controllers
- Ensure controller is connected before starting the game
- Check if controller is recognized by your OS:
LinuxmacOS
- Verify SDL2 gamepad support:
Mouse look not working
Mouse look not working
- Press M to toggle mouse look on/off
- Check if MOUSE directive in .cub file is set to FALSE
- Ensure window has focus (click on the game window)
Analog stick drift
Analog stick drift
The deadzone is set to 8000/32767 (~24%). If drift persists:
- Clean or recalibrate your controller
- Increase
CONTROLLERS_DEADZONEinsrc/ft_mlx_utils/controllers/controllers.h:controllers.h
Controls feel too fast/slow
Controls feel too fast/slow
Adjust velocity constants in Rebuild after changes:
headers/cub3d.h:cub3d.h:Keyboard-only mode stuck
Keyboard-only mode stuck
Press K to toggle keyboard-only mode off. This mode disables mouse and gamepad input.
Next Steps
Creating Maps
Design custom levels and configure entities
Building
Compile and test your changes