title: Move SKSpriteNode with Physics
body: <p>I am trying to move an SKSpriteNode with physics by setting it's velocity. I am doing this on top of another SKNode (the map) that is part of the SKScene. Positions of "cities" are stored in custom <code>Location</code> objects.</p>
  
  <p>I know the location of the initial SKSpriteNode (the ship) and I know the desired location. From what I've read, I can move the sprite by setting it's velocity. I do so like this:</p>
  
  <pre><code>float dy = _player.desiredLocation.yCoordinate - _mapNode.pin.position.y;
  float dx = _player.desiredLocation.xCoordinate - _mapNode.pin.position.x;
  _mapNode.pin.physicsBody.velocity = CGVectorMake(dx, dy);
  </code></pre>
  
  <p>This is all inside the <code>didSimulatePhysics</code> function inside the SKScene. Once the user taps a <code>Location</code>, I find the position and set the velocity. This seems to work well the FIRST time, but the sprite moves all over the place in subsequent times. Any idea what could be going wrong here?</p>
  
  <p>PS: Setting <code>skView.showsPhysics = YES;</code> puts the circle of the physics body way off the position  of the sprite.</p>
  
  <p>In the map node:</p>
  
  <pre><code>self.pin = [SKSpriteNode spriteNodeWithImageNamed:[IPGameManager sharedGameData].world.player.ship.type];
  self.pin.userInteractionEnabled = NO;
  self.pin.position = CGPointMake([IPGameManager sharedGameData].world.player.location.xCoordinate, [IPGameManager sharedGameData].world.player.location.yCoordinate);
  self.pin.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:10.0];
  self.pin.physicsBody.dynamic = YES;
  self.pin.physicsBody.allowsRotation = NO;
  self.pin.physicsBody.friction = 0.0;
  self.pin.physicsBody.linearDamping = 0.0;
  [self addChild:self.pin];
  </code></pre>