Search Unity

Question hand velocity with rotation problems.

Discussion in 'XR Interaction Toolkit and Input' started by JKGameDev, Oct 7, 2020.

  1. JKGameDev

    JKGameDev

    Joined:
    Apr 28, 2017
    Posts:
    11
    I need some help with some xr movement. I am making a space station and I want full realistic zero-g movement and rotation. I used Valem's wall climbing tutorial to get the grabbing movement down, and did something similar for the rotation. It is working really nicely, but only when your rotation is (0, 0, 0). When you rotate yourself and try to grab the wall and move around, the velocity sends you in the wrong direction. At 90 degrees if you push right, it sends you up, and at 180 degrees on the y and z axis all the movements are completely flipped. I've tried several methods for getting the velocity to match with the rotation, such as tranform.forward, TransformDirection, and multiplying the velocity by the rotation, but have had little success.

    I basically just need a way to account for rotation in the hand velocity.

    upload_2020-10-6_20-34-36.png
     
  2. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    I'm late to the party and just started looking seriously at XR a couple days ago, but one thing I noticed a few minutes ago when trying to get a character head to look at the VR camera was that the VR camera node seems to be reported in XR Rig coordinates instead of world coords. I'm not too sure about that because my XR rig is aligned with 0 rotation, but the position offset was indeed that. (I.e., to get a character to look at the VR camera, I had to add the XR rig position to the camera position. We can't just use the camera game object like we could in Unity 5, but I digress).

    So I'm just guessing here, but if all these devices through GetDeviceAtXRNode() are indeed XR rig coordinates, you might just need to rotate the hand controller velocity vector into world coords. Something like this might be worth a try:


    Input.Devices.GetDeviceAtXrNode(.........out handVelocityLocal);

    Vector3 handVelocityWorld = xrRig.transform.rotation * handVelocityLocal;

    (Quaternion math is not commutative, so make sure the rotation is before the multiplication sign, not after.)

    If that doesn't work, I'd try to figure out which coordinate system the GetDeviceAtXrNode() is reporting everything in. Maybe it's XR Rig frame or maybe it's in the camera frame or something similar. Either way, this kind of thing is typically just a transformation from one coordinate system to another. In the case of a velocity (or any other direction) vector, that's just a matter of multiplying by one transform.rotation or another. The trick is in figuring out which transform that is.

    Sorry for not handing over an exact solution, but I'm new to XR and am not sure. This is the line of thinking I'd use to figure it out though.