How to reference the position of a scene object in a script?
I am fairly new to lens studio. I am trying to learn in general how to tell which parameters of an object I can reference or modify once I have added the object to the input of a script. Specifically, I am trying to reference the positions of two object in order to perform a distance check to see if they are close enough for the hit count to be increased
I am using hand tracking and a screen image
Hey @...
I dont know much about scripting, but i found a script from @... which could work on your issue.
"you are able to get distance between object right now in Lenses
var pos1 = someComponent.getTransform().getWorldPosition();
var pos2 = someOtherComponent.getTransform().getWorldPosition();
var dist = pos1.distance(pos2);
This distance will be in centimeters.
But this won't work with object detected by Object Detection Template, as it find only coordinates in 2D, not in 3D."
Check this post from him out.
Some links which could help you ( not sure if they work to 100%) :
Link1
Link2
I hope i could help you.
Cheers,
SirQu3ntin
Thanks, Sir Qu3ntin,
I will give these a try
Assuming your two images have ScreenTransform components on them, you can do something like below. (You can pull it out of the onUpdate function and just call it when necessary if you don't need it to constantly compute distance every frame).
Since the points are being computed in screen space, they are limited to values between 0 and 1, so that affects the calculated distance result (i.e. it's not in centimeters).
The anchorSpaceToScreenSpace() function simply converts one coordinate system to another (I nabbed that bit from one of the lens studio template scripts at some point).