I’m aware of how to check if two circles are intersecting one another. However, sometimes the circles move too fast and end up avoiding collision on the next frame.
My current solution to the problem is to check circle-circle collision an arbitrary amount of times between the previous position and it’s current position.
Is there a mathematical way to find the time it takes for the two circle to collide? If I was able to get that time value, I could move the circle to the position at that time and then collide them at that point.
Edit: Constant Velocity
I’m assuming the motion of the circles is linear. Let’s say the position of circle A’s centre is given by the vector equation
Ca = Oa + t*DawhereCa = (Cax, Cay)is the current positionOa = (Oax, Oay)is the starting positiontis the elapsed timeDa = (Dax, Day)is the displacement per unit of time (velocity).Likewise for circle B’s centre:
Cb = Ob + t*Db.Then you want to find t such that
||Ca - Cb|| = (ra + rb)whereraandrbare the radii of circles A and B respectively.Squaring both sides:
||Ca-Cb||^2 = (ra+rb)^2and expanding:
(Oax + t*Dax - Obx - t*Dbx)^2 + (Oay + t*Day - Oby - t*Dby)^2 = (ra + rb)^2From that you should get a quadratic polynomial that you can solve for t (if such a t exists).