menu_bookDocumentation
Controller Input: Analog Sticks, Haptics, Motion Controls, and Local Multiplayer
s&box supports gamepad/controller input with analog sticks, haptics/rumble, motion controls, and local multiplayer.
Detecting Controller
Check Input.UsingController to see if the player is using a gamepad.Analog Inputs
Direct analog values from sticks and triggers:CSHARP
float moveX = Input.GetAnalog( InputAnalog.LeftStickX );
float aimAmount = Input.GetAnalog( InputAnalog.LeftTrigger );Haptics/Rumble
Set vibration intensity per motor with duration:CSHARP
Input.TriggerHaptics( 0.5f, 0.7f, 0.2f, 0f, 1000 ); // left, right, leftTrigger, rightTrigger, msOr use presets with scaling:
CSHARP
Input.TriggerHaptics( HapticEffect.HardImpact, 1.2f, 2f, 0.5f );Stop all with Input.StopAllHaptics().
Motion Controls
Access gyroscope/accelerometer if available:CSHARP
InputMotionData motionData = Input.MotionData;
if ( motionData is not null )
{
Vector3 acceleration = motionData.Acceleration;
Vector3 angularVelocity = motionData.AngularVelocity;
}Local Multiplayer
Use Input.ControllerCount and Input.PlayerScope( index ):CSHARP
using ( Input.PlayerScope( playerIndex ) )
{
if ( Input.Pressed( "Jump" ) )
{
// This player's jump
}
}
Was this helpful?