Hello,
My game is 2D. In my game i want move player tank with Accelerometer. I want to move tank in left,right,up and down directions only. So, i am using acceleration.x and acceleration.y only.
Following is my code to move tank. Now my problem is tank not moves smoothly. Gravity and kfilter are used in Accelerometer but i don't know how to use it.
Pls give me one example to solve this problem.
-(void)accelerometerUIAccelerometer *)accelerometer didAccelerateUIAcceleration *)acceleration
{
float x = (float)acceleration.x;
float y = (float)acceleration.y;
if(y > 0.3) //Left
{
playertank.position = cpv(playertank.position.x - 2, playertank.position.y);
}
else if(y < -0.3) //Right
{
playertank.position = cpv(playertank.position.x + 2, playertank.position.y);
}
else if(x > -0.3)//up
{
playertank.position = cpv(playertank.position.x, playertank.position.y + 2);
}
else if(x < -0.7)//Down
{
playertank.position = cpv(playertank.position.x , playertank.position.y - 2);
}
}
Thanks in advance.