title: Apply Linear Impulse to Rotation of Sprite- Cocos2d/Box2D
body: <p>I have an arrow and a ball. The anchorPoint for the arrow is on the bottom. All I need to do is have the sprite be able to rotate with touch, then a linear impulse is applied to the ball and shot in the direction the arrow is pointing to.</p>
  
  <p>E.G.</p>
  
  <p>Say you rotate the arrow 70 degrees then press the fire button. The ball is then shot in a 70 degree angle.</p>
  
  <p>Currently, this is what I am using but the ball does not shoot in the direction the arrow is pointing too.</p>
  
  <p>Rotates arrow with touch.</p>
  
  <pre><code>-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  {
      UITouch *touch = [touches anyObject];
  
      //acquire the previous touch location
      CGPoint firstLocation = [touch previousLocationInView:[touch view]];
      CGPoint location = [touch locationInView:[touch view]];
  
      //preform all the same basic rig on both the current touch and previous touch
      CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location];
      CGPoint firstTouchingPoint = [[CCDirector sharedDirector] convertToGL:firstLocation];
  
      CGPoint firstVector = ccpSub(firstTouchingPoint, _arrow.position);
      CGFloat firstRotateAngle = -ccpToAngle(firstVector);
      CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);
  
      CGPoint vector = ccpSub(touchingPoint, _arrow.position);
      CGFloat rotateAngle = -ccpToAngle(vector);
      CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
  
      //keep adding the difference of the two angles to the dial rotation
      arrowRotation += currentTouch - previousTouch;
  }
  </code></pre>
  
  <p>Fire Button to shoot the ball in the direction the arrow is pointing too.</p>
  
  <pre><code>-(void) fireBall: (id)sender
  {
      [self unscheduleUpdate];
  
      direction = arrowRotation;
      b2Vec2 force = b2Vec2(direction, 24.8);
      _ballBody-&gt;ApplyLinearImpulse(force, _ballBody-&gt;GetWorldCenter());
  }
  </code></pre>
  
  <p>Any help is greatly appreciated!
  Thanks in advance!</p>