|
A ball bouncing off a corner |
Johan Halmén
Member #1,550
September 2001
|
I have a pools like game and I'm struggling with balls bouncing at corners. In more general terms: a circle moving towards the corner of a rectangle. In frame n it doesn't overlap yet, in frame n+1 it does overlap. I need a new velocity vector and a new position for frame n+1. I think I've got the mathematics for it right, but it is very complicated and I'm looking for simplifications to keep frame rate high. Any ideas? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Cage
Member #1,277
March 2001
|
As in it hits right in the corner? [edit] In that case, treat it like a 45 degree wall right there . If not, bounce off each wall of the corner in succession.
----- |
Johan Halmén
Member #1,550
September 2001
|
Perhaps I wasn't clear enough. The circle hits the corner of the rectangle from outside. If it would hit both walls successively, it should actually hit the imaginary extensions of the walls. Doing this it wouldn't hit the actual corner at all. edit: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Cage
Member #1,277
March 2001
|
Ahh, hitting the outside corner of a rectangle. Well I don't know how it would reall react but could you simply treat that as a 45 degree wall? Perhaps it might bounce at 2x the angle, or just slightly more than 1x, not sure though . I guess you could start at, say, bouncing it at 2x the angle and then manipulate it to see what looks right... sorry, I'm not much of a physics person . [edit] Judging from that post, I'm not much of an English person, either .
----- |
Johan Halmén
Member #1,550
September 2001
|
As I said, I think I know how it happens in real physics, I shall return to that. In my approximation I simply do this: when the circle would overlap I create a vector from the corner to the centre of the overlapped circle and add this vector to the velocity vector. Then I move the overlapped circle along this new vector just so much that it won't overlap. Then I draw it. It behaves almost correct, but not quite. It sometimes gets more velocity from the bounce, instead of loosing velocity. edit: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
|