Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
Angle information(degree) between AR camera and target object on a plane

I have a question, please help and thanks! I want to know how to show the Angle information(degree) between AR camera and target object on a plane. (Using Smartphone) And I want to know how to "code" with Unity and AR Foundation.

I tried using some code(below), but it seems only work on Distance, not work on Angle...

Thank again!

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);
            
    }
}

}

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I would check that the ray hits:

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")     
}

Also I would make sure that the target has a collider and that the layer mask is correct.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda