Reading out distance

So i’m trying to read the distance between the player and the camera. I have a intel realsense d415 and I want to stop skeleton tracking of an player if he comes to close to the camera (or display a message). I have searched around a bit but so far no luck. I use the onlostuser now to stop tracking and disable the model, which I want to keep. But I want to display a message (or maybe disable the model) when the player gets to close, because then reading the skeleton starts being inaccurate and the model can start to glitch. Any tips?

Thanks in advance :slight_smile:

I would maybe use the userTracker to watch the distances

  • it will continue to report the distance of a user regardless of the skeleton track

I dont have runnning system to test this on - BUT in C# something like this would likely work for you



// add a event callback in the start area
void Start()
NuitrackManager.OnUpdateEvent += WatchUser;

// define the callback
void WatchUser(nuitrack.UserFrame frame)
if (frame.Users.Length > 0)
// got a user or users
// loop thru and check distances
foreach (User user in frame.Users)
// get the user position
var userPosition = user.Real.ToVector3();

             float someDistance = 500.f;
             if ( userPosition.z > someDistance)
                  // warn user they are getting too close

    // no users - remove any warnings


1 Like

Hi Westa,

Thanks a lot for the info, it sure helped me! I changed it a bit, OnUserTrackerUpdate didn’t work. So i Used: userTracker.OnUpdateEvent += WatchUser;

I kept the rest almost the same, Only made the actual Vector3 (userposition), since it wasn’t declared yet. Hopefully this helps other people.

Right now it works with a simple Debug.log. Now i’ll find a way to make it disable skeleton. Thanks for the info, I’ll report back if I have further questions!


Patrick Klokgieters

So a little update: I currently have it disable my model when i walk to close, however I need to find a way to force nuitrack to remove the tracked user. When you call OnLostUserEvent, it removes the user from the list, but this is only called when a user walks out of the screen or is not trackable anymore, Is there any way to force this? Like say: Remove user that is to close.? I noticed this is done in the OnLostUserEvent with the subscribe/usagecount. Maybe it’s possible to force this? These functions are otherwise not directly reachable.

Tommorow is a new day to search around, but if anyone knows a way, it’s appreciated.