|
Problems with algorithm for bouncing between two circles |
Loki66
Member #17,089
May 2019
|
Hi everyone sorry for the bad english source code /*newVelX1 = (firstBall.speed.x * (firstBall.mass – secondBall.mass) + /*newVelY1 = (firstBall.speed.y * (firstBall.mass – secondBall.mass) + /*newVelX2 = (secondBall.speed.x * (secondBall.mass – firstBall.mass) + /*newVelY2 = (secondBall.speed.y * (secondBall.mass – firstBall.mass) + d_enemy_dx = ld_dx1, d_enemy_dy = ld_dy1; Explanation: the part that deals with the bounce is this: newVelX1 = (firstBall.speed.x * (firstBall.mass – secondBall.mass) + (2 * secondBall.mass * secondBall.speed.x)) / (firstBall.mass + secondBall.mass); The problem is that this works if both circles move, if one is stopped the calculation is wrong. If the two circles are equal, they have the same mass (firstBall.mass and secondBall.mass) If the circle two does not move secondBall.speed.x = 0 Am I not understanding or does this algorithm not work? |
MikiZX
Member #17,092
June 2019
|
Seeing that even the algorithm you present does not work with super-fast moving circles(because between two frames of collision calculation it can happen that circles that should have collided end up going "through" each-other without a collision detection) - I will go again and suggest this long video: This video also has part 2 and that can be a help if you wish to expand this proposed collision later on. If you will have super-fast moving circles on your screen then possibly you will have to use some sort of circle-circle sweep collision solutions (but I am sorry - I do not know of a good tutorial for this). |
Loki66
Member #17,089
May 2019
|
I can't understand spoken English, and I think videos are a waste of time. |
Johan Halmén
Member #1,550
September 2001
|
Check this thread. It's only 12 years old. In short: When two circles collide, draw a wall through the collision point. The wall becomes a tangent to both circles. Divide each circle's velocity vector into a tangent component and a normal component (tangent component is parallel to the wall, normal component is perpendicular). Exchange the normal components between the circles. Add the components for each circle to get their new velocities. Before adding, you might want to reduce the normal components by a percentage (energy dissipation). A circle which stands still will therefore continue perpendicular to the wall, while the other circle continueas in the wall direction. This is a well known fact among pool players: The que ball continues 90 degrees away from the ball it hit. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Loki66
Member #17,089
May 2019
|
Thanks, that's what I need. |
piccolo
Member #3,163
January 2003
|
On YouTube you can use capsions so you can read what they are saying wow |
Loki66
Member #17,089
May 2019
|
thank you all I also tried the algorithm suggested by gary_ramsgate and this works well too. |
|