S&box Wiki

Revision Difference

vr-input#563961

<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.⤶ Input from VR is available 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 object, you probably want to use the VR Tracked Object component instead⤶ // Replicate the transform of the left hand onto the entity⤶⤶ Entity.Transform = Input.VR.LeftHand.Transform;⤶ // 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 much of the mainstream controllers as possible.⤶ You can access the inputs for each hand's controller. This is generic to to support as many of the mainstream controllers as possible. ```csharp public override void Simulate( Client cl )⤶ public override void OnUpdate() { if ( Input.VR.RightHand.ButtonA.IsPressed ) { // Do something when the A button is pressed⤶ // Do something when the A button on the ⤶⤶ // Do something when the A button is pressed⤶⤶ } } ``` ## Finger Tracking <upload src="a5727/8dabe5aa5cb45d7.mp4" size="22604970" name="vrfingertracking(1).mp4" /> ⤶ You can get the finger curl and splay, which allows you to pose the fingers to match your real life fingers in game.⤶ 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. ```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 ``` The hands in the video up there are available on Asset.Party: [VR Terry Hand - Left](https://asset.party/shadb/hand_toon_left) [VR Terry Hand - Right](https://asset.party/shadb/hand_toon_right) ## Head ⤶ Headset position and rotation can also be accessed simply through Input.VR.Head. ⤶ ⤶⤶ Head mounted device position and rotation can also be accessed simply through Input.VR.Head. ⤶ ⤶⤶ Headset position and rotation can also be accessed 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 );⤶ Log.Info( 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. For example, quest controller vibration frequency tends to be a lot less responsive than other controllers. 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.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.