Rotation in Unity is not working

I would like to rotate one prefab in Unity, currently the position is tracked but I have some problems with the rotation.

Quaternion jointOrient = Quaternion.Inverse((CalibrationInfo.SensorOrientation) * joint.ToQuaternion()); 
CreatedJoint[q].transform.localRotation = jointOrient;

Hi Antonio,

Please describe your issue in more detail. Is it rotated incorrectly or not rotated at all? Do you need to use Quaternion.Inverse?

Here is a possible solution:

Quaternion jointOrient = (CalibrationInfo.SensorOrientation) * joint.ToQuaternion();
CreatedJoint[q].transform.localRotation = jointOrient;

Thanks for the response, actually is not rotating in a correct way, and also I tried with out using of Quaternion.Inverse.

The the main code for the rotation purpose is the next one:


    void Start()
    {

        CreatedJoint = new GameObject[typeJoint.Length];
        for (int q = 0; q < typeJoint.Length; q++)
        {
            if (q == 8)
            {
                CreatedJoint[q] = Instantiate(LeftHand);
                CreatedJoint[q].transform.SetParent(transform);

            } else if (q == 9)
            {
                CreatedJoint[q] = Instantiate(RightHand);
                CreatedJoint[q].transform.SetParent(transform);
            }
        }
        message = "Skeleton created";
    }


    void Update()
    {
        // Track the first user
        if (CurrentUserTracker.CurrentUser != 0)
        {
            Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            message = "Skeleton found";

            for (int q = 0; q < typeJoint.Length; q++)
            {
                if (q == 8)
                {
                    nuitrack.Joint joint = skeleton.GetJoint(typeJoint[q]);

                    // For the position 
                    UnityEngine.Vector3 newPosition = 0.001f * joint.ToVector3(); // This is a 3D unity Vector 
                    CreatedJoint[q].transform.localPosition = newPosition;

                    // For the rotation
                    //Quaternion jointOrient = Quaternion.Inverse((CalibrationInfo.SensorOrientation) * joint.ToQuaternion());
                    //CreatedJoint[q].transform.localRotation = jointOrient;
                }
                else if (q == 9)
                {
                    nuitrack.Joint joint = skeleton.GetJoint(typeJoint[q]);

                    // For the position 
                    UnityEngine.Vector3 newPosition = 0.001f * joint.ToVector3(); // This is a 3D unity Vector 
                    CreatedJoint[q].transform.localPosition = newPosition;

                    // For the rotation
                    //Quaternion jointOrient = Quaternion.Inverse((CalibrationInfo.SensorOrientation) * joint.ToQuaternion());
                    //CreatedJoint[q].transform.localRotation = jointOrient;
                }
            }

        }
        else
        {
            message = "Skeleton not found";
        }
    }

Can you please record a video that shows this issue? Everything should work fine without Quaternion.Inverse.

I removed the Quaternion.Inverse but still not working

video

Looks like it is inverted 180 degrees.

You can try to add offset. You can do it in one of two ways:

  1. Add 180 degrees to the axis (axes) in your code (the rotation part).
  2. In Unity editor: create an empty object and move it using Nuitrack. Make the object in your video (a hand with a ski pole?) a child to this object. Inside the empty object, rotate the hand with a ski pole by 180 degrees.