SteamVR

SteamVR

galaxy5599 Jan 1, 2020 @ 6:17am
[steamvr, unity] How to get pointing/aiming direction of any controller?
I would like to get the Quaternion indicating the pointing direction of the hand regardless of controller. And I believe I'm doing it wrong.

Using Unity 2019.2 with latest steamvr package (2.5.0 (sdk 1.8.19)).

oRight is the [CameraRig]->Controller (right).transform

I do
Vector3 vOrigin = oRight.position; Quaternion qRotation = oRight.rotation; qRotation = qRotation * Quaternion.Euler(45, 0, 0); //todo: works for oculus (why?), same on vive wands, index controller or wmr? vPointingDirection = qRotation * Vector3.forward;

I have Oculus Rift CV1 and 45 degree rotation around the X axis is what i must do from the .rotation, or it will point upwards in the ceiling.

Now I suspect this angle of 45 will be different with different controllers, so I would like to get an adjusted rotation that points where the index finger is pointing when you stretch it out valid for all controllers without having to do any rotation of my own...

Also, why do I have to bind a 'pose' to the controller to even get .position and .rotation to report something other then zero? and to show the controller Model?
< >
Showing 1-5 of 5 comments
Ben Jan 8, 2020 @ 10:34am 
Put a game object as a child of the hand, then use Quaternion.LookRotation(transform.forward) to get the direction that one is pointing
galaxy5599 Jan 8, 2020 @ 12:22pm 
The problem is that the rotations are different for the controller model and the controller pointing direction. Both of them exists somewhere in steamvr, but for the model to render correctly the transform must be correct.


Here is what I ended up doing.

Have two poses,
Pose_right - bind to the 'Right hand grip' in steamvr settings.
Pose_right_tip - bind to the 'Right hand tip' in steamvr settings.
(maybe named something else in English version)

Only Pose_right is bound to the SteamVR_Behaviour_Pose script for the controller in Unity, this will set the transform for 'Controller (right)'.

oRight is the [CameraRig]->Controller (right).transform
oCameraRig is [CameraRig].transform

SteamVR_Action_Pose poseActionR = SteamVR_Input.GetAction<SteamVR_Action_Pose>("Pose_right_tip"); Vector3 vOrigin = oRight.position; Quaternion qRotation = oCameraRig.rotation * poseActionR[SteamVR_Input_Sources.RightHand].localRotation; vPointingDirection = qRotation * Vector3.forward;

I still don't fully understand the Pose concept. Mostly since only one pose will be correct for rendering the controller object.
motar2k Jan 8, 2020 @ 5:41pm 
added to ask a question
Ben Jan 9, 2020 @ 9:16am 
You mean trying to get where the finger is pointing?

ive been struggling with that a bit today. Ive used:

hand.skeleton.GetBone((int)SteamVR_Skeleton_JointIndexEnum.indexTip);

to get the end of the finder, then made an gameobject a child of that, which does the raycast


Poses - you might only need one for holding a controller, but the idea is that you might need to be holding something else in your game, e.g. a gun or sword and might need another hand pose for them
galaxy5599 Jan 9, 2020 @ 2:32pm 
I don't know, but a pose in steamvr_input seems to be only a point around the controller with a relative direction (a hard coded value depending on the current controller oculus/valve)... accessible only if you bind them to a pose, and one of those poses will set the controller model transform... these kind of things should not be left for the user to rebind in steamvr_input or the controller may end up pointing in the wrong direction breaking the game...

Still I think there is more to the pose concept I'm not understanding...

Here is a Unity and a SteamVR input screenshot.
https://imgur.com/a/wsINF75
< >
Showing 1-5 of 5 comments
Per page: 1530 50

Date Posted: Jan 1, 2020 @ 6:17am
Posts: 5