【问题标题】:How to solve transform.position assign attempt for is not valid如何解决 transform.position 分配尝试无效
【发布时间】:2017-02-21 09:21:26
【问题描述】:

我使用统一并在 Kinect 360 上工作是版本 1,我创建新场景并正在处理 2D 空间,我还在场景中心创建 UI 按钮和另一个 UI 按钮,但我将其修改为小圆圈和我把它命名为游标 现在我想用右手移动光标 希望被 Kinect 检测到 所以我陷入了

的错误
{
transform.position assign attempt for 'cursor' is not valid .Input position    is{-Infinity,-777756757673984982383290000000000000000000000,0,0} 
} 

我的代码在这里

void Update () {

    KinectManager manager = KinectManager.Instance;

    if (DepthImageViewer.Instance.jointColliders != null)
    {
        if (!isInited)
        {
            isInited = true;
            initialPosition = new Vector2((DepthImageViewer.Instance.jointColliders[11].transform.position.x + 50) * 19.2f, (DepthImageViewer.Instance.jointColliders[11].transform.position.y + 50) * 10.8f);//, DepthImageViewer.Instance.jointColliders[11].transform.position.z);
        }

        Vector2 newPos = new Vector2((DepthImageViewer.Instance.jointColliders[11].transform.position.x + 50) * 19.2f - offstX, (DepthImageViewer.Instance.jointColliders[11].transform.position.y + 50) * 10.8f - offstY) - initialPosition;//, DepthImageViewer.Instance.jointColliders[11].transform.position.z) - initialPosition;
        Debug.Log(DepthImageViewer.Instance.jointColliders[11].transform.position);
    }
    else
    {
        Debug.Log("not joint colliders");
    }
} 

【问题讨论】:

    标签: c# unity3d kinect


    【解决方案1】:

    大家好,我找到了解决办法

    public int offstX= 937;
    public int offstY= 520;
    
    bool isInited=false;
    void Update() {
    
        uint playerID;
        if(manager != null){
            playerID = manager.GetPlayer1ID();
        }else{ playerID = 0; }
    
        if(playerID <= 0) {
            //reset all the position to the initial values 
            if (transform.position != initialPosition) {
                transform.position = initialPosition;
            }
            //reset all the rotation to the initial values 
            if (transform.rotation != initialRotation)
            {
                transform.rotation = initialRotation;
            }
            for (int i = 0; i < bones.Length; i++)
            {
                bones[i].gameObject.SetActive(true);
                bones[i].transform.localPosition = Vector3.zero;
                bones[i].transform.localRotation = Quaternion.identity;
                if (SkeletonLine)
                {
                    lines[i].gameObject.SetActive(false);
                }
            }
            return;
        }
        //set the user position in space 
        Vector3 positionPointMan = manager.GetUserPosition(playerID);
        */
        float initialXposition = transform.localPosition.x;
        float initialYposition = transform.localPosition.y;
        float nextXposition=0;
        float nextYposition=0;
        KinectManager manager = KinectManager.Instance; // call the Kinect instance
    
        if (DepthImageViewer.Instance.jointColliders != null)
        {
            if (manager.Player1Calibrated && isInited == false)
            {
                isInited = true;
                Debug.Log("Kinect See Your hand");
                transform.localPosition = new Vector2(0, 0);
                nextXposition = transform.localPosition.x;
                nextYposition = transform.localPosition.y;
                if (initialXposition != nextXposition && initialYposition != nextYposition)
                {
                    Debug.Log("I moved the cursor the the initial pisition");
                }
                else
                    Debug.Log("Sorry I didn't translate the cursor");
            } else if (manager.Player1Calibrated && isInited == true)
            {
                float XvalueAre = DepthImageViewer.Instance.jointColliders[11].transform.localPosition.x * 192.0f + 184430.4f;
                float YvalueAre = DepthImageViewer.Instance.jointColliders[11].transform.localPosition.y *108.0f + 58832.1f;
    
    
            Vector2 newPos = new Vector2(XvalueAre - offstX, YvalueAre - offstY);// - initialPosition ,DepthImageViewer.Instance.jointColliders[11].transform.position.z) - initialPosition;
                Debug.Log("Your Hand X position => " + DepthImageViewer.Instance.jointColliders[11].transform.localPosition.x);
                Debug.Log("Your Hand Y position => " + DepthImageViewer.Instance.jointColliders[11].transform.localPosition.y);
                Debug.Log("Your Converted Hand X position => " + XvalueAre);
                Debug.Log("Your Converted Hand Y position => " + YvalueAre);
                transform.position = newPos;
    
            }
    
    
    
    
    
         }
        else
            Debug.Log("Erreur remplir joints colliders ");
    
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 2014-06-22
      • 1970-01-01
      相关资源
      最近更新 更多