1

I am working for an enterprise who wants to measure the distance between the man who is holding the camera and an object placed in the real world. But, they want to do it, WITHOUT focusing the camera on that object.

I have seen ARCore, and I watched that you can place an object (Android icon in the videos) in the real world, and it stays where you have placed it all time (also when you don't look at it). That's a good first step.

But the real thing I want to know is that if I can measure the distance between the camera object (it is supposed to be the person holding the mobile phone) and that object placed in the real world (Android icon) without focusing it with the camera.

Maybe with a raycast or simply with a vector3.Distance, I don't know. But is this possible? Any ideas? Because I have tried a lot of things, but they don't work...

Thank you so much in advance.

MarGin
  • 2,078
  • 1
  • 17
  • 28

1 Answers1

0

Just use Vector3.Distance. Keep track of the camera object and the instantiated object, and do:

float distance = Vector3.Distance(YourCameraObject.transform.position, YourAugmentedObject.transform.position)
JackMini36
  • 621
  • 1
  • 5
  • 14
  • Hi Jack. What is exactly the meaning of Keeping track the camera and the object? I am new on AR tools and concepts. Thank you! – James Vlogames Apr 16 '18 at 06:25
  • Just have a global variable to store the camera gameobject, and the instantiated android logo gameobject, so you can access them later. This is not an AR thing, it is more a general programming thing so I would suggest looking into basic C# programming if you are not familiar enough with it. – JackMini36 Apr 16 '18 at 07:25
  • Hum, I know how to make that haha I am not new on C# or Unity, but I supposed that "keep track" means to focus the camera to the gameobejct or to check all time the virtual space created, or something like that. – James Vlogames Apr 16 '18 at 07:51
  • Sorry for the confusion. No, I mean keep a reference to the camera globally, so you can use it later. Or access it with Camera.main.gameObject if it is tagged as the main camera. Do the same with the instantiated object. Then you can very easily use the Distance function. – JackMini36 Apr 16 '18 at 08:03