AvatarController.MoveAvatar C# (CSharp) Method

MoveAvatar() public method

public MoveAvatar ( uint UserID ) : void
UserID uint
return void
    void MoveAvatar(uint UserID)
    {
        if(Root == null || Root.parent == null)
            return;
        if(!KinectManager.Instance.IsJointTracked(UserID, (int)KinectWrapper.SkeletonJoint.HIPS))
            return;

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

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

            XOffset = MirroredMovement ? trans.x * MoveRate : -trans.x * MoveRate;
            YOffset = trans.y * MoveRate;
            ZOffset = -trans.z * MoveRate;
        }

        float xPos;
        float yPos;
        float zPos;

        // If movement is mirrored, reverse it.
        if(MirroredMovement)
            xPos = trans.x * MoveRate + XOffset;
        else
            xPos = -trans.x * MoveRate - XOffset;

        yPos = trans.y * MoveRate - YOffset;
        zPos = -trans.z * MoveRate - ZOffset;

        // If we are tracking vertical movement, update the y. Otherwise leave it alone.
        Vector3 targetPos = new Vector3(xPos, VerticalMovement ? yPos : 0f, zPos);
        Root.parent.localPosition = Vector3.Lerp(Root.parent.localPosition, targetPos, 3 * Time.deltaTime);
    }