There are the codes: - (void)startMoving:(ccTime)dt { CGPoint pos = CGPointZero; float objPOSX = self.position.x; float objPOSY = self.position.y;
float angle = self.rotation; float radian = angle*M_PI/180; int quadrant = [self getObjQuadrant];
switch (quadrant) { case 1: pos.x = objPOSX + tan(radian) * (sqrt(2 * pow(objSpeed,2) / (1 + pow(tan(radian),2)))); pos.y = objPOSY + sqrt(2 * pow(objSpeed,2) / (1 + pow(tan(radian),2))); break; case 2: pos.x = objPOSX + tan(M_PI - radian) * (sqrt(2 * pow(objSpeed,2) / (1 + pow(tan(M_PI - radian),2)))); pos.y = objPOSY - sqrt(2 * pow(objSpeed,2) / (1 + pow(tan(M_PI - radian),2))); break; case 3: pos.x = objPOSX - tan(M_PI + radian) * (sqrt(2 * pow(objSpeed,2) / (1 + pow(tan(M_PI + radian),2)))); pos.y = objPOSY - sqrt(2 * pow(objSpeed,2) / (1 + pow(tan(M_PI + radian),2))); break; case 4: pos.x = objPOSX - tan(- radian) * (sqrt(2 * pow(objSpeed,2) / (1 + pow(tan(- radian),2)))); pos.y = objPOSY + sqrt(2 * pow(objSpeed,2) / (1 + pow(tan(- radian),2))); break; default: break; } NSLog(@"Angle------------- %f",angle); if (isnan(angle)) { self.position = self.position; } else { self.position = pos; } }