Kinect.AvatarController.MoveAvatar C# (CSharp) Method

MoveAvatar() protected method

protected MoveAvatar ( System.Int64 UserID ) : void
UserID System.Int64
return void
        protected void MoveAvatar(Int64 UserID)
        {
            if (!kinectManager || !kinectManager.IsJointTracked(UserID, (int)KinectInterop.JointType.SpineBase))
                return;

            // Get the position of the body and store it.
            Vector3 trans = kinectManager.GetUserPosition(UserID);

            // If this is the first time we're moving the avatar, set the offset. Otherwise ignore it.
            if (!offsetCalibrated)
            {
                offsetCalibrated = true;

                xOffset = trans.x;  // !mirroredMovement ? trans.x * moveRate : -trans.x * moveRate;
                yOffset = trans.y;  // trans.y * moveRate;
                zOffset = !mirroredMovement ? -trans.z : trans.z;  // -trans.z * moveRate;

                if (posRelativeToCamera)
                {
                    Vector3 cameraPos = posRelativeToCamera.transform.position;
                    Vector3 bodyRootPos = bodyRoot != null ? bodyRoot.position : transform.position;
                    Vector3 hipCenterPos = bodyRoot != null ? bodyRoot.position : bones[0].position;

                    float yRelToAvatar = 0f;
                    if (verticalMovement)
                    {
                        yRelToAvatar = (trans.y - cameraPos.y) - (hipCenterPos - bodyRootPos).magnitude;
                    }
                    else
                    {
                        yRelToAvatar = bodyRootPos.y - cameraPos.y;
                    }

                    Vector3 relativePos = new Vector3(trans.x, yRelToAvatar, trans.z);
                    Vector3 newBodyRootPos = cameraPos + relativePos;

                    //				if(offsetNode != null)
                    //				{
                    //					newBodyRootPos += offsetNode.transform.position;
                    //				}

                    if (bodyRoot != null)
                    {
                        bodyRoot.position = newBodyRootPos;
                    }
                    else
                    {
                        transform.position = newBodyRootPos;
                    }

                    bodyRootPosition = newBodyRootPos;
                }
            }

            // Smoothly transition to the new position
            Vector3 targetPos = bodyRootPosition + Kinect2AvatarPos(trans, verticalMovement);

            if (isRigidBody && !verticalMovement)
            {
                // workaround for obeying the physics (e.g. gravity falling)
                targetPos.y = bodyRoot != null ? bodyRoot.position.y : transform.position.y;
            }

            if (bodyRoot != null)
            {
                bodyRoot.position = smoothFactor != 0f ?
                    Vector3.Lerp(bodyRoot.position, targetPos, smoothFactor * Time.deltaTime) : targetPos;
            }
            else
            {
                transform.position = smoothFactor != 0f ?
                    Vector3.Lerp(transform.position, targetPos, smoothFactor * Time.deltaTime) : targetPos;
            }
        }