I see shoulderCenter code in the code, so you are probably using the Microsoft Kinect SDK v1.x. In this case, the skeletal joints are as follows:

Microsoft Kinect SDK v1.x Height Score
Suppose we have a function that can calculate the distance between two joints. We call this function d(joint1, joint2) .
Suppose also that we have defined a function that can calculate the midpoint between two joints (note that the following is just pseudocode):
function avg(joint1, joint2) { avg_joint.x = (joint1.x + joint2.x) / 2.0; avg_joint.y = (joint1.y + joint2.y) / 2.0; avg_joint.z = (joint1.z + joint2.z) / 2.0; return avg_joint; }
A good algorithm for estimating user height might be the following (note that this is just pseudo-code):
torso_height = d(HEAD, SHOULDER_CENTER) + d(SHOULDER_CENTER, SPINE) + d(SPINE, HIP_CENTER) + d(HIP_CENTER, avg(HIP_RIGHT, HIP_LEFT)); left_leg_height = d(HIP_LEFT, KNEE_LEFT) + d(KNEE_LEFT, ANKLE_LEFT) + d(ANKLE_LEFT, FOOT_LEFT); right_leg_height = d(HIP_RIGHT, KNEE_RIGHT) + d(KNEE_RIGHT, ANKLE_RIGHT) + d(ANKLE_RIGHT, FOOT_RIGHT); tot_height = torso_height + (left_leg_height + right_leg_height) / 2.0;
If all connections are well monitored , this algorithm works very well. However, it is possible (and this actually happens quite often) that some joints are excreted . On this page, from the MSDN documentation, you can see how to check if the joints have been moved to C #.
If a judgment is deduced, the chances of its wrong position increase. Thus, opportunities that rate height will also increase.
The following method can be used to check if all connections are tracked well. It returns false if at least one connection is not well monitored; otherwise, it returns true :
function areJointsWellTracked(JointCollection joints) { foreach (Joint joint in joints) if(joint.TrackingState != JointTrackingState.Tracked) return false; return true; }
So, what you can do to improve the user's height rating is to calculate it ONLY when all joints are well tracked.
In addition, we consider the possibility of always providing an average value of more than one of the last height values. For example, you can remember the last ten height values in an array, and then provide each time the average value of these values. This will help reduce the impact of noise in your measures.
Your problem
Your code looks like a simplified version of the algorithm I just described. Therefore, the only reason you can get these strange values is because tracking is not working. My suggestion is to try to use the above areJointsWellTracked method and evaluate the height only when all connections are well tracked.
Additional Note for Microsoft Kinect SDK v2
For developers using SDK v2, note that skeletal joints are not defined, as in SDK v1.x. The following figure shows this difference:

Due to the different positions and definitions of some joints, the above algorithm for estimating the height should be edited as follows:
torso_height = d(HEAD, NECK)+ d(NECK, SPINE_SHOULDER) + d(SPINE_SHOULDER, SPINE_MID) + d(SPINE_MID, SPINE_BASE) + d(SPINE_BASE, avg(HIP_RIGHT, HIP_LEFT)); left_leg_height = d(HIP_LEFT, KNEE_LEFT) + d(KNEE_LEFT, ANKLE_LEFT) + d(ANKLE_LEFT, FOOT_LEFT); right_leg_height = d(HIP_RIGHT, KNEE_RIGHT) + d(KNEE_RIGHT, ANKLE_RIGHT) + d(ANKLE_RIGHT, FOOT_RIGHT); tot_height = torso_height + (left_leg_height + right_leg_height) / 2.0;
You can find an interesting discussion on how to gauge user height using the Microsoft Kinect SDK v2 in this link .