AR Glasses/연습프로젝트

연습프로젝트 _ 큐브 위에 큐브 있으면 캐치하기

minquu 2021. 10. 1. 09:31
반응형

기존 예제

    void Update ()
    {
        dotValue = Mathf.Cos(Mathf.Deg2Rad * (angleRange / 2));
        direction = target.position - transform.position;
        if (direction.magnitude < distance)
        {
            if (Vector3.Dot(direction.normalized, transform.forward) > dotValue)
                isCollision = true;
            else
                isCollision = false;
        }
        else
            isCollision = false;

    }

 

기존 예제의 문제는 transform.forward 라서 계속 현재 오브젝트의 위치를 캐치해서 문제였음

 

 

 

문제해결

    private bool OnUpCubeNow(Transform target)
    {
        dotValue = Mathf.Cos(Mathf.Deg2Rad * (angleRange / 2));
        direction = target.position - transform.position;
        if (direction.magnitude < distance)
        {
            if (Vector3.Dot(direction.normalized, InitUpVector) > dotValue)
                return true;
            else
                return false;
        }
        else
            return false;
    }

 

 

 

 

큐브 생성시 처음에 초기화 했던 Vector3 값을 넣어주었음 

 

반응형