Find relative 3D position between 2 image targets in Unity

–2 votes
asked Apr 16, 2019 by markhurry (270 points)
Hi

I have a unity3D scene with two image targets. How do I find the relative positions between the two image targets once the targets have been found?

Thanks

Mark

2 Answers

–1 vote
answered Apr 16, 2019 by zhnagjian (11,130 points)
Hello,

Do you mean that you need to display the distance between the two image targets?
commented Apr 16, 2019 by markhurry (270 points)
Hi

thanks for the response.

I want to be able to know the relative positions between the two target images once they have been found so that I can move a model from one target image towards the second target image in code.
–1 vote
answered Apr 23, 2019 by ngc6543 (1,670 points)
Calculate the position difference between the transforms of target A and target B.

Transform targetA, targetB;

Vector3 posDifferenceFromAtoB = targetB.position - targetA.position;

By normalizing the posDifference you may get the direction vector from A to B.

If you are not familiar with Unity API, check here : https://docs.unity3d.com/Manual/index.html

If you are not familiar with some essential mathmatics for (3D) game development, maybe you'd better study basic Linear Algebra first, like this one : https://www.youtube.com/watch?v=fNk_zzaMoSs
commented Apr 23, 2019 by markhurry (270 points)
Hi

thanks for your answer. Not really what I am looking for as I am more interested in the internal  workings of ImageTargetBehaviour and ImageTarget classes and how to access the relevant gameobjects and transforms. You have have given me a beginners guide to computer graphics and Unity which I don't need.  I have now found an answer. Thanks Mark
commented Apr 23, 2019 by ngc6543 (1,670 points)
edited Apr 23, 2019 by ngc6543
Ha, but that's what you've asked!
commented Apr 23, 2019 by markhurry (270 points)
Not quite. You responded about Unity.  I was asking about TargetImage and how it works with Unity. Thanks
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...