Changing Character Location in Unity

When using Unity, the character model would reset to near the 0,0,0 location regardless of where the original location of the character object is. I was wondering if there was a location to change this location so I won’t need to have the character near the center at all time.

Hi Jeff,

Please check out the code below:

    using UnityEngine;
    using System.Collections.Generic;

    // This can be any class
    public class RiggedAvatar : MonoBehaviour
    {
        [Header("Rigged model")]
        [SerializeField] List<ModelJoint> modelJoints;

        [SerializeField] TPoseCalibration poseCalibration;

        // Offset for the position of the avatar
        Vector3 positionOffset;

        void Start()
        {
            poseCalibration.onSuccess += PoseCalibration_onSuccess;

            /*
             * Your code
             * ...
             */
        }

        void OnDestroy()
        {
            poseCalibration.onSuccess -= PoseCalibration_onSuccess;
        }
        
        // Calculate the offset for avatar position during calibration 
        void PoseCalibration_onSuccess(Quaternion rotation)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            Vector3 torsoPos = TorsoPosition(skeleton);
            positionOffset = torsoPos;
        }

        Vector3 TorsoPosition(nuitrack.Skeleton skeleton)
        {
            return Quaternion.Euler(0f, 180f, 0f) * CalibrationInfo.SensorOrientation * (0.001f * skeleton.GetJoint(nuitrack.JointType.Torso).ToVector3());
        }

        void Update()
        {
            if (CurrentUserTracker.CurrentSkeleton != null)
                ProcessSkeleton(CurrentUserTracker.CurrentSkeleton);
        }

        void ProcessSkeleton(nuitrack.Skeleton skeleton)
        {
            //Calculate the model position: take the Torso position and invert movement along the Z axis
            Vector3 torsoPos = TorsoPosition(skeleton);        

            // Apply the offset for transformation (use the local coordinates)
            transform.localPosition = torsoPos - positionOffset;

            /*
             * Your arbitrary code
             * ...
             */
        }
    }

To make sure that this solution works correctly, you have to create an empty object (for example, called “PositionCorrection”) and drag-and-drop your avatar to this object. Its local coordinates should be (0, 0, 0). After this, you can set PositionCorrection to the required position. After calibration, your avatar will be placed to this position.