Garry's Mod Wiki

Kinect developing

Developing for the Kinect is easier than you'd think.

Bone Points

The kinect provides us with a number of vectors representing specific bones. These are encoded into the usercommand (in the same way that mouse buttons and view angles are) and are available on the player object serverside, and in multiplayer - for prediction purposes - clientside.

To access these points you can call

ply:MotionSensorPos( point_id )

Note that these positions aren't in world coordinates - so you will have to multiply them to get them to a usable size.

To access specific bones you can use these enums:

SENSORBONE.HIP SENSORBONE.SPINE SENSORBONE.SHOULDER SENSORBONE.HEAD SENSORBONE.SHOULDER_LEFT SENSORBONE.ELBOW_LEFT SENSORBONE.WRIST_LEFT SENSORBONE.HAND_LEFT SENSORBONE.SHOULDER_RIGHT SENSORBONE.ELBOW_RIGHT SENSORBONE.WRIST_RIGHT SENSORBONE.HAND_WRIGHT SENSORBONE.HIP_LEFT SENSORBONE.KNEE_LEFT SENSORBONE.ANKLE_LEFT SENSORBONE.FOOT_LEFT SENSORBONE.HIP_RIGHT SENSORBONE.KNEE_RIGHT SENSORBONE.ANKLE_RIGHT SENSORBONE.FOOT_RIGHT

motionsensor

The motionsensor offers direct access to the sensor clientside, and a few utility functions sharedside.

motionsensor.DebugBones

This table contains subtables of bone ids allowing you to iterate it and draw bones.

for k, v in ipairs( motionsensor.DebugBones ) do debugoverlay.Line( ply:MotionSensorPos( v[1] ), ply:MotionSensorPos( v[2] ), 0.5 ) end

motionsensor.IsAvailable()

Clientside - will return true if we have detected that there's a kinect connected to the PC.

motionsensor.IsActive()

Clientside - will return true if a kinect is connected - and active (ie - Start has been called).

motionsensor.Start()

Clientside - this starts access to the kinect sensor. Note that this usually freezes the game for a couple of seconds.