void Update () { if (BodySourceManager == null) { return; } _BodyManager = BodySourceManager.GetComponent<BodySourceManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetData(); if (data == null) { return; } List<ulong> trackedIds = new List<ulong>(); foreach(var body in data) { if (body == null) { continue; } if(body.IsTracked) { trackedIds.Add (body.TrackingId); } } List<ulong> knownIds = new List<ulong>(_Bodies.Keys); // First delete untracked bodies foreach(ulong trackingId in knownIds) { if(!trackedIds.Contains(trackingId)) { Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } bodyTracked = false; foreach(var body in data) { if (body == null) { continue; } if (bodyTracked){ continue; } if(body.IsTracked) { if(!_Bodies.ContainsKey(body.TrackingId)) { // Draws stick figure of body to screen //_Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId); } //RefreshBodyObject(body, _Bodies[body.TrackingId]); // New head tracking code (testing) Kinect.Joint headJoint = body.Joints[Kinect.JointType.Head]; if (headJoint.TrackingState == Kinect.TrackingState.Tracked) { Kinect.KinectSensor sensor = _BodyManager.getSensor(); Kinect.DepthSpacePoint dsp = sensor.CoordinateMapper.MapCameraPointToDepthSpace(headJoint.Position); x = dsp.X; y = dsp.Y; bodyTracked = true; //Debug.Log (x); } } } }