Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //for obj_ball in the collision event with obj_paddle:
  2.  
  3. //calculations
  4. ballSize = bbox_right - bbox_left;
  5. paddleSize = other.bbox_right - other.bbox_left;
  6. ballMiddle = bbox_left + ballSize/2;
  7. paddleMiddle = other.bbox_left + paddleSize/2;
  8. bounceDistance = abs(ballMiddle-paddleMiddle);
  9. bounceAngle = bounceDistance/paddleSize;
  10.  
  11. //perform bounce
  12. vspeed *= -1; \\multiply vspeed by -1 (reverse the vertical direction)
  13. hspeed = speed*bounceAngle;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement