Guest User

Untitled

a guest
Jun 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. float dist = sqrt(pow(self.pos.x - ball.pos.x, 2) + pow(self.pos.y - ball.pos.y, 2));
  2.  
  3. float minLength = (self.sprite.contentSize.height/2 + ball.sprite.contentSize.height/2);
  4. float width = self.pos.x - ball.pos.x;
  5. float height = self.pos.y - ball.pos.y;
  6. float delta = minLength/dist;
  7. float x, y = 0.0;
  8.  
  9. x = width * delta;
  10. y = height * delta;
  11.  
  12. x -= width;
  13. y -= height;
  14.  
  15. x *= -1;
  16. y *= -1;
  17.  
  18. ball.pos = CGPointMake(ball.pos.x + x, ball.pos.y + y);
Add Comment
Please, Sign In to add comment