S&box Wiki

VR Input

VR Input

Input from VR is available 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 object, you probably want to use the VR Tracked Object component instead gameobject.Transform = Input.VR.LeftHand.Transform;

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

public override void OnUpdate() { if ( Input.VR.RightHand.ButtonA.IsPressed ) { // Do something when the A button is pressed } }

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. The VR Hand component does this for you.

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

The hands in the video up there are available on Asset.Party:

VR Terry Hand - Left

VR Terry Hand - Right

Head

Headset 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 ) { Log.Info( trackedObject.Transform.Position, trackedObject.Transform.Rotation ); }

Haptics

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. For example, quest controller vibration frequency tends to be a lot less responsive than other controllers.