Tengo una pregunta, por favor ayuda y gracias! Quiero saber cómo mostrar la información de ángulo (grado) entre la cámara AR y el objeto de destino en un avión. (Usando un teléfono inteligente) Y quiero saber cómo "codificar" con Unity y AR Foundation.
Intenté usar un código (a continuación), pero parece que solo funciona en Distancia, no funciona en Ángulo ...
¡Gracias de nuevo!
void Start () { //get the components private ARRaycastManager RayManager; private GameObject visual; public Camera CameraStart; public Text textField2; public Text textField; float distance; float angle; RayManager = FindObjectOfType<ARRaycastManager>(); visual = transform.GetChild(0).gameObject; } void Update () { // shoot a raycast from the center of the screen List<ARRaycastHit> hits = new List<ARRaycastHit>(); RayManager.Raycast(new Vector2(Screen.width / 2, Screen.height / 2), hits, TrackableType.Planes); RaycastHit hit; //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // check if we hit an AR plane, update the position and rotation if(hits.Count > 0) { transform.position = hits[0].pose.position; transform.rotation = hits[0].pose.rotation; distance = Vector3.Distance(CameraStart.transform.position, transform.position); textField.text = distance.ToString("N2") + "meter"; Physics.Raycast(transform.position, out hit); angle = Vector3.Angle(hit.normal, transform.forward); textField2.text = angle.ToString("N2") + "degree"; if(!visual.activeInHierarchy) visual.SetActive(true); } }}
Comprobaría que el rayo incide:
if (Physics.Raycast(transform.position, out hit)) { angle = Vector3.Angle(hit.normal, transform.forward); textField2.text = angle.ToString("N2") + "degree"; } else { Debug.LogError("Did not hit") }También me aseguraría de que el objetivo tenga un colisionador y que la máscara de capa sea correcta.