S&box Wiki

VR Input

VR Input

Input from VR is available both clientside and serverside in Simulate() all through Input.VR.

Hands

Both hands are represented as Input.VR.LeftHand and Input.VR.RightHand, this struct contains the position and rotation of each hand.

// Replicate the transform of the left hand onto the entity Entity.Transform = Input.VR.LeftHand.Transform;

You can access the inputs for each hand's controller. This is generic to to support as much of the mainstream controllers as possible.

public override void Simulate( Client cl ) { if ( Input.VR.RightHand.ButtonA.IsPressed ) { // Do something when the A button on the } }

Finger Tracking

You can get the finger curl and splay, which allows you to pose the fingers to match your real life fingers in game.

var curl = Input.VR.LeftHand.GetFingerValue( FingerValue.ThumbCurl ); var splay = Input.VR.LeftHand.GetFingerValue( FingerValue.ThumbIndexSplay ); curl = Input.VR.LeftHand.GetFingerCurl( 0 ); // 0 - 4 splay = Input.VR.LeftHand.GetFingerSplay( 0 ); // 0 - 3

Head

Head mounted device position and rotation can also be accessed simply through Input.VR.Head.

Trackers

You can get the position and rotation of any puck trackers, and also your base stations if you're not using a quest.

foreach( var trackedObject in Input.VR.TrackedObjects ) { DebugOverlay.Axis( trackedObject.Transform.Position, trackedObject.Transform.Rotation ); }

Haptics

These are clientside only currently

Haptic vibrations can be triggered per hand using Input.VrHand.TriggerHapticVibration you can call this as often as you like, if a haptic event is already running it will be interrupted immediately.

// Pulse right hand haptics with an amplitude scaled from velocity Input.VR.RightHand.TriggerHapticVibration( 0f, 200.0f, Math.Clamp( 0.4f + Velocity.Length / 500f, 0.4f, 0.8f ) );

Something to consider is different controllers have different limitations to their haptics, something I've noticed with Oculus controllers is the frequency is a lot less responsive than other controllers for example.