Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float dist = sqrt(pow(self.pos.x - ball.pos.x, 2) + pow(self.pos.y - ball.pos.y, 2));
- float minLength = (self.sprite.contentSize.height/2 + ball.sprite.contentSize.height/2);
- float width = self.pos.x - ball.pos.x;
- float height = self.pos.y - ball.pos.y;
- float delta = minLength/dist;
- float x, y = 0.0;
- x = width * delta;
- y = height * delta;
- x -= width;
- y -= height;
- x *= -1;
- y *= -1;
- ball.pos = CGPointMake(ball.pos.x + x, ball.pos.y + y);
Add Comment
Please, Sign In to add comment