views:

33

answers:

0

Hi, Please look at the code first....

- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
{   

    b2Vec2 localPoint;
localPoint.Set(0,0);        
    if (acceleration.x>1.5 || acceleration.y>1.5) {
    b2Vec2 mVelik = ballBody->GetLinearVelocityFromLocalPoint(localPoint);
    b2Vec2 forca( fabs(acceleration.x *factor), fabs(acceleration.y*factor));
    ///////////check the current direction///////////////////////

                if (mVelik.x>0) {

                    mVelik += forca;
                }

                else {
                    mVelik.x+=-fabs(acceleration.x *factor);

                }


            b2Vec2 force = b2Vec2(mVelik.x, mVelik.y);
            b2Vec2 p = ballBody->GetWorldPoint(b2Vec2(acceleration.x, acceleration.y));
            ballBody->ApplyForce(force, p);
}

}

1.>first i detect shake of iPhone. 2.>then i measure the current velocity of ball using BOX2d code. 3.>then i try to increase the current velocity of ball and want to direct the ball towards the shaking direction....

is this approach right??? I got some abnormal motion of ball...... the ball moves very slowly.... and after sometimes the ball start rotating around its axis.....??

can help??