For a project I need to make a flashgame with the Kinect for Xbox.
Using the AS3NUI library to get acces to most of the Kinect functions worked well for me.
It’s a pong game where you have to move your paddle vertically through hand movement.
I’ve tried a few ways of moving the paddle, but none of them is really accurate. And if they are more accurate, they aren’t smooth at all anymore.
My first methode was setting the paddle.y to the value of the hand.y.
_paddleLeft.y = (userLeft.leftHand.position.y);
Of course the result was terrible.
This was my next try:
_paddleLeft.y = (userLeft.leftHand.position.rgbRelative.y * stage.stageHeight*2);
This was pretty accurate, but not smooth at all, and sometimes it was very hard to reach the top of the stage, or the bottom.
At last, I tried something else. I saved the hands last Y position, and checked if the new position was higher or lower, and on that I moved the paddle up or down.
currYLeft = userLeft.leftHand.position.rgb.y;
currYRight = userRight.rightHand.position.rgb.y;
if (currYLeft > prevYLeft + 10){
isDown1 = true;
isUp1 = false;
}else if( currYLeft < prevYLeft - 10){
isDown1 = false;
isUp1 = true;
}
prevYLeft = userLeft.leftHand.position.rgb.y;
prevYRight = userRight.rightHand.position.rgb.y;
In another enterframehandler, I make them move up or down.
This is the most smooth way I achieved, but it isn’t very accurate anymore. There is some kind of delay wich you don’t have with the first two ways.
I would like to know if it is possible to make the movement smooth AND accurate at the same time? And how this is possible.
If you already have an accurate solution, May be you can try putting some easing in it for the smoothness. You might wanna try using this instead in the enterFrame loop
0.3 can be altered to other numbers between 0 and 1, depending on the easing speed you want…That’s my best guess, hope this helps ^^