terminalCode Example
Controller Input
Handle gamepad/controller input in s&box.
Detecting Controllers
CSHARP
// Check if player is using controller
if (Input.UsingController)
{
// Show controller glyphs, adjust UI
}
// Get connected controller count
int controllers = Input.ControllerCount;Analog Inputs
CSHARP
// Direct analog inputs (0-1 range)
float moveX = Input.GetAnalog(InputAnalog.LeftStickX);
float moveY = Input.GetAnalog(InputAnalog.LeftStickY);
float aimX = Input.GetAnalog(InputAnalog.RightStickX);
float aimY = Input.GetAnalog(InputAnalog.RightStickY);
// Triggers (not all controllers have analog triggers)
float leftTrigger = Input.GetAnalog(InputAnalog.LeftTrigger);
float rightTrigger = Input.GetAnalog(InputAnalog.RightTrigger);Auto-Mapped Input
CSHARP
// Works for both controller and keyboard/mouse
Vector3 moveInput = Input.AnalogMove; // WASD or Left Stick
Angles lookInput = Input.AnalogLook; // Mouse or Right StickHaptics/Rumble
CSHARP
// Direct motor control
Input.TriggerHaptics(
leftMotor: 0.5f, // 0-1 intensity
rightMotor: 0.7f,
leftTrigger: 0.2f,
rightTrigger: 0f,
duration: 1000 // milliseconds
);
// Preset effects
Input.TriggerHaptics(HapticEffect.HardImpact,
lengthScale: 1f,
frequencyScale: 1f,
amplitudeScale: 1f);
// Stop all vibration
Input.StopAllHaptics();Motion Controls
CSHARP
InputMotionData motionData = Input.MotionData;
if (motionData is not null)
{
Vector3 acceleration = motionData.Acceleration; // Accelerometer
Vector3 angularVelocity = motionData.AngularVelocity; // Gyroscope
}Local Multiplayer
CSHARP
// Query specific controller
int playerIndex = 0;
using (Input.PlayerScope(playerIndex))
{
// All Input.* calls now query this controller
if (Input.Pressed("jump"))
{
// Player 1 jumped
}
}
Was this helpful?