- Home /
Calculate distance between AR object and camera
I want to know how I can calculate the distance between an AR-object and the camera filming it, in order to make the object turn to the camera when being within a certain radius of the object. Would really appreciate some concrete code examples of how to do this, given that you already have a marker and working virtual character placed on it, and already know how to turn the object in the cameras direction. Thanks!
Answer by SneakyLeprechaun · Sep 17, 2017 at 08:45 PM
Would Vector3.Distance() help? It returns the distance between the two positions. Something like Vector3 Dist = Vector3.Distance(Camera.main.transform.position,transform.position) if(Dist <= TurnDist){ //do stuff }
just put this in the update function on your object that wants to turn.
Hope that helps!
Your answer
![](https://koobas.hobune.stream/wayback/20220612135051im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can measure distance between camera and object placed with ARCore without focusing the camera? 0 Answers
How to get distance between camera and object? 1 Answer
How to measure the distance between an Augmented Reality marker and camera? 0 Answers
ARCore tracking maximum distance 2 Answers
Checking camera distance between object in a AR game 1 Answer