๐Ÿ“ฆ about ๐Ÿงป posts

Over the past few days I’ve been playing with the Kinect SDK with GMod. It has been super, super, super fun. Super fun!

The outputs from the kinect are really simple. You set it up, query it, it updates, and then you get a bunch of vectors.

So you draw them in-game – and what does it look like?

Awesome, so then you draw lines between the right vectors and bam, you got yourself a skeleton!

Which looks cool, but we want to control ragdolls, right? So all our stuff is clientside right now. We need to treat the kinect like any other controller – and pack that shit into the usercommand.. so it gets sent to the server like any other button. The positions are then available serverside on the player object.. player:GetKinectPos( int ).

So I tried setting the physics bone positions and angles. I believe this is what John B did in his implementation a while back.

That kind of works. But it’s kind of shitty. Kind of laggy, and weird. This is because we’re setting the positions every serverside think.. which really isn’t often enough.

We add some code in the ragdoll entity – setting the positions in VPhysicsUpdate.. which is called all the time (when the ragdoll isn’t sleeping).

That’s cool! Obviously all the positions and the angles are fucked up – but it’s super responsive!

One of the issues with the positions is that the kinect skeleton isn’t really the same as our skeleton. We need to make some adjustments.

What I do is lerp between the kinect positions to build a table of ‘valvebiped’ positions. Just to get as close as possible. We can over-lerp and under-lerp if we need to.

Then I use that table to work out the angles between the limbs. The kinect doesn’t know about angles of limbs – the sdk does offer a function but it just processes the position vectors to work out the angles. This seemed like a waste of network bandwidth to me – so we just work out the angles ourselves on the server. This is something we’d probably have to do anyway since the kinect angles aren’t going to match our target skeleton.

Once we have the angles we just have to ‘solve’ the ragdoll using those angles. This makes all of the limbs the expected, normal sizes.

And it’s as easy as that!


Add a Comment

An error has occurred. This application may no longer respond until reloaded. Reload ๐Ÿ—™