I do not find what’s the problem. I am using ccpToAngle() to find an angle of vector but can’t get proper angle. My ball is launched/initial position at cpp(170,40) and using swipe i want to throw it.
I wrote to find an angle,
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [touch locationInView: [touch view]];
CGPoint vector = ccpSub(location, ccp(170 ,40));
normalVector = ccpNormalize(vector);
float angleRads = ccpToAngle(normalVector);
float angle = CC_RADIANS_TO_DEGREES(angleRads);
}
but here if i swiped more then angle is increased. I think, swipe in same line/direction the angle should be same every time. but here, I am getting angle between 70 to 90 degrees only, if swipe more then angle is near to 60,66 degrees.
I want angle between 0 to 180 degrees. is it possible that it can consider ccp(170 ,40) as axis origin & find an angle of vector in Cocos2d?
Thanks In advance.
if you want to find an angle of swipe you have to use trigonometry here..
Here is some that can help you..
this how you detect that ball is touched
Now on touch end we can calculate the direction.
this is how we calculate direction.