3

So I am making a game that's like slime volleyball. Basically, my two main players, or objects, are half circles on either side, I have a net in the middle, and a ball. My problem is I can't figure out how to make the ball bounce of a semi circle so that it follows both the angle and direction. I've tried looking it up, but all of them are either about walls or rectangles, not bouncing off a circular object. Any code or ideas would help.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
Luke Fairway
  • 87
  • 1
  • 5
  • Can you provide some code, based on that, it would be easier to try and help you. Also in what language are you programming? – Shane van Wyk May 12 '15 at 23:55
  • look into box2d. it's available for most languages you would be asking stack overflow about – Kai Qing May 13 '15 at 00:05
  • This is really more of a math/physics question. Have you tried implementing the physics in code yet? – MooseBoys May 13 '15 at 00:19
  • can you draw a tangent to the circle at the point of bounce? you can then treat that tangent as your "wall" and bounce. But it's really a math problem, not a programming problem. Or, physics, if your wall has any worldly attributes. – Dinesh May 13 '15 at 01:10
  • im using java, sry about that, but yea. i think i have the math somewhat figured out now thanks! ...ill try to upload the code tonight to show where i am at right now... – Luke Fairway May 15 '15 at 18:19

1 Answers1

1

"Take a semicircle, point it upwards, shine parallel rays of light straight down at it, and let those rays reflect off it. The envelope of the reflected rays will be half of a nephroid":


          ParallelRaysCirc
          Image source: John Baez.
More directly, assume you have a ray r along your ball path. Find the intersection point p of r with your semicircle C. Compute the tangent t at p. Compute the normal n at p. Reflect r over n to r'.
Joseph O'Rourke
  • 4,346
  • 16
  • 25