- Home /
How to create lock on UI element when trackable detected?
Hi all,
I've been playing around with vuforia's AR - and created a white UI crosshair that sits center screen, and turns purple when tracking my image target. The effect I'm trying to create is that the crosshair locks on to the card/image target when it's tracked.
Shown in my attached images, the problem is that the crosshair moves away from the target as I move the camera. I understand why, and a workaround could be to add another crosshair onto the purple border image - the problem is that this wouldn't be a smooth transition when the target is found.
Thanks for any help in advance
Answer by fafase · Sep 22, 2017 at 07:05 PM
If I get it right you want the crosshair to stick on the marker when detected.
You could try to use :
https://docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.html
Then get the position of the object in the scene (by default it is set in the origin (0,0,0)) and pass it to the method.
The result is where on the screen you want the crosshair to be drawn. Passing that value to your UI element should do it. You should not need conversion since the UI elements are using world position on the canvas.