How to set objects enable/disable by Distance Check
How to switch between Disable and Enable for an object depending on the position of the body?
I've used the "Distance Check" from Behavior Script. Then I set ObjectA and B as "Orthographic Camera" and "Center" from BodyTracking. However, it doesn't change even when I move.
I'd like to make a filter that shows a face mask only when I close to the camera like closer than 7 inch. The one that the face mask will disappear when the user will get away even the face or body itself is detected.
Thanks.
Hello FY!
The easiest way to achieve what you want would be to use the Perspective Camera in your scene and the HeadBinding object with it.
The orthographic camera has a offset with the main scene (as you can see on the left part of your scene and the face mask object is a flat 2d object whose position does not change based on your head position. That's why it's best to use the HeadBinding object.
Try attach a script with the code below to any of your objects to see if their position changes based on head movement:
script.createEvent("UpdateEvent").bind(function(){
print(script.getSceneObject().getTransform().getWorldPosition());
});
When you check the logger you'll find out that when this script is attached to the Face Mask object it shows:
And when attached to Head Binding:
That being said, your behavior script logic is totally correct! I would suggest leaving Distance same for both behavior script unless you want a different distance for enable/disabling.
It might be helpful to know the distance between objects in order to set it in behavior, you can find out the distance between 2 objects with this added to an empty script:
//@input SceneObject obj1
//@input SceneObject obj2
var distance = 0;
script.createEvent("UpdateEvent").bind(function(){
distance = script.obj1.getTransform().getWorldPosition().distance(script.obj2.getTransform().getWorldPosition());
print(distance);
});
Hope this might be of help, happy creating!
Dear Nico,
Thank you so much for the answer. It was truly helpful! I've succeeded. I was also able to attach the script and see the numbers.
I appreciate your support!!