Question by
ChoiKyongKofuu · Apr 07, 2017 at 10:30 AM ·
kinectdepth
How can I use the depth of the Kinect for my overlayObject ?
Hello !
I'm currently working on a kind of squash game and I want to use the depth provided by the Kinect v2 as my overlayObject z coordinate. The overlayObject x and y are based on the right hand posJoint.
Right now my code is like that :
void Update ()
{
KinectManager manager = KinectManager.Instance;
if (manager && manager.IsInitialized () && foregroundCamera) {
//backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
if (backgroundImage && (backgroundImage.texture == null)) {
backgroundImage.texture = manager.GetUsersClrTex ();
}
// get the background rectangle (use the portrait background, if available)
Rect backgroundRect = foregroundCamera.pixelRect;
PortraitBackground portraitBack = PortraitBackground.Instance;
if (portraitBack && portraitBack.enabled) {
backgroundRect = portraitBack.GetBackgroundRect ();
}
// overlay the joint
long userId = manager.GetUserIdByIndex(playerIndex);
int iJointIndex = (int)trackedJoint;
if (manager.IsJointTracked (userId, iJointIndex))
{
Vector3 posJoint = manager.GetJointPosColorOverlay(userId, iJointIndex, foregroundCamera, backgroundRect);
posJoint.z = -8f;
if (posJoint != Vector3.zero)
{
if (overlayObject)
{
overlayObject.position = posJoint;
}
}
}
else
{
// make the overlay object invisible
if (overlayObject && overlayObject.position.z > 0f)
{
Vector3 posJoint = overlayObject.position;
posJoint.z = -8f;
overlayObject.position = posJoint;
}
}
}
}
As you can see, I restricted the overlayObject z axis to -8, but I'd like it to go forward when the right hand is near the camera and backwards when the hand is far from it.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612114756im_/https://answers.unity.com/themes/thub/images/avi.jpg)