title: Automatic sprite rotation in SpriteKit
body: <p>I am currently making an iPhone game using SpriteKit in which two archers fire arrows at each other in an attempt to take away all of their opponent's health. I've got the mechanism for firing the arrow when the user drags back on the screen, but am wondering if there is a way to make the arrow sprite rotate in mid air as it follows the arc (facing upwards immediately after release and facing downward immediately prior to landing) so that it actually looks as if it were fired from a bow in real life.</p>
  
  <p><a href="https://i.stack.imgur.com/l6RgQ.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l6RgQ.gif" alt="How it currently looks"></a></p>
  
  <p>This is the piece of code that is ran when the user's touch ends. You can see where I apply the impulse but I am not sure how to go about implementing the rotation. I understand how I could get the initial rotation to match the angle of the trajectory line using simple trigonometry, but don't know how to make it rotate with its arc.</p>
  
  <pre><code>func touchUp(atPoint pos : CGPoint) {
  
      if arrowFired == false &amp;&amp; firstTouchMade == true &amp;&amp; pointOne != nil {
  
          //Set pointTwo
          pointTwo = pos
  
          //Define the vert/hor of the pull-back
          let verticalLeg = ((pointOne?.y)! - (pointTwo?.y)!)
          let horizontalLeg = ((pointOne?.x)! - (pointTwo?.x)!)
  
          //Apply the impulse
          arrow?.run(SKAction.applyImpulse(CGVector(dx: horizontalLeg / 9, dy: verticalLeg / 9), duration: 0.001))
          arrow?.physicsBody?.affectedByGravity = true
  
          let array = [trajectoryLine, trajectoryLabel] as [Any]
          removeChildren(in: array as! [SKNode])
  
          arrowFired = true
      } else if firstTouchMade == false &amp;&amp; zoomingIn == false {
          zoomingIn = true
          cameraNode.run(SKAction.move(to: (arrow?.position)!, duration: 1), completion: {
              self.firstTouchMade = true
              self.zoomingIn = false
          })
          cameraNode.run(SKAction.scale(by: 0.5, duration: 1))
  
      }
  }
  </code></pre>
  
  <p>Sorry if this is an obvious question, I am relatively new to programming, Swift, and SpriteKit especially.</p>