S&box Wiki

Revision Difference

vr-input#547955

<cat>Code.VR</cat>⤶ <title>VR Input</title>⤶ ⤶ # VR Input⤶ ⤶ Input from VR is available both clientside and serverside in Simulate() all through Input.VR.⤶ ⤶ ## Hands⤶ ⤶ <upload src="a5727/8dabdcb06b430d5.mp4" size="6096770" name="vrhands.mp4" />⤶ ⤶ Both hands are represented as Input.VR.LeftHand and Input.VR.RightHand, this struct contains the position and rotation of each hand.⤶ ⤶ ```csharp⤶ // 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.⤶ ⤶ ```csharp⤶ public override void Simulate( Client cl )⤶ {⤶ if ( Input.VR.RightHand.ButtonA.IsPressed )⤶ {⤶ // Do something when the A button on the ⤶ }⤶ }⤶ ```⤶ ⤶ ## Finger Tracking⤶ ⤶ <upload src="a5727/8dabdcb132ecd84.mp4" size="5152720" name="vrfingertracking.mp4" />⤶ ⤶ You can get the finger curl and splay, which allows you to pose the fingers to match your real life fingers in game.⤶ ⤶ ```csharp⤶ 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 access simply through Input.VR.Head. ⤶ ⤶ ## Trackers⤶ ⤶ <upload src="a5727/8dabdcb19fdb1ab.mp4" size="3405378" name="vrtrackers.mp4" />⤶ ⤶ You can get the position and rotation of any [puck trackers](https://www.vive.com/us/accessory/tracker3/), and also your base stations if you're not using a quest.⤶ ⤶ ```csharp⤶ foreach( var trackedObject in Input.VR.TrackedObjects )⤶ {⤶ DebugOverlay.Axis( trackedObject.Transform.Position, trackedObject.Transform.Rotation );⤶ }⤶ ```⤶ ⤶ # Haptics⤶ ⤶ <note>These are clientside only currently</note>⤶ ⤶ 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.⤶ ⤶ ```csharp⤶ // 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.