title: iOS Sprite Kit: How to make Sprite follow Touches
body: <p>I'm new to Sprite Kit and I'm wondering how you can make a sprite follow the touches. For example, my player sprite is on the bottom of the screen. When I tap on the top of the screen, the player sprite should move to the touch point with a certain speed - and if I move my finger it should always be pointing towards the touch point. This is how I tried to implement it:</p>
  
  <pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  
      for (UITouch *touch in touches) {
  
          CGPoint location = [touch locationInNode:self];
  
          CGPoint diff = rwSub(location, self.player.position);
          CGPoint norm = rwNormalize(diff);
  
          SKAction *act = [SKAction moveByX:norm.x * 10 y:norm.y * 10 duration:0.1];
          [self.player runAction:[SKAction repeatActionForever:act] withKey:@"move"];
  
  
      }
  }
  
  - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
      for (UITouch *touch in touches) {
  
          CGPoint location = [touch locationInNode:self];
  
          CGPoint diff = rwSub(location, self.player.position);
          CGPoint norm = rwNormalize(diff);
  
          SKAction *act = [SKAction moveByX:norm.x * 10 y:norm.y * 10 duration:0.1];
          [self.player runAction:[SKAction repeatActionForever:act] withKey:@"move"];
      }
  
  }
  </code></pre>
  
  <p>However, the sprite moves very laggy when moving the finger. Is there a way I can make the movement nice and smooth?</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>EDIT: I think I have found a solution I modified the touchesMoved function:</p>
  
  <pre><code>- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
  {
      for (UITouch *touch in touches) {
  
          [self.player removeActionForKey:@"move"];
          CGPoint location = [touch locationInNode:self];
  
          CGPoint diff = rwSub(location, self.player.position);
          CGPoint norm = rwNormalize(diff);
  
          [self.player setPosition: rwAdd(self.player.position, rwMult(norm, 2))];
          SKAction *act = [SKAction moveByX:norm.x * 10 y:norm.y * 10 duration:0.01];
          [self.player runAction:[SKAction repeatActionForever:act] withKey:@"move"];
          }
      }
  
  }
  </code></pre>