Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!