I don't understand authors login when calculating collisions between two circles (bubbles). Here is the Calculating collisions section.
Author writes:
The bubble being fired follows a set of coordinates defined by the equations:
px = ex + tdx py = ey + tdy
where px and py are points on the trajectory of the bubble’s center point. The calculation of px and py happens in jQuery’s animate method and is the standard equation for moving a point along a line. Next, we’ll calculate t at the closest point on this line to the center of the bubble that we’re checking against:
var t = dx * distToBubble.x + dy * distToBubble.y;
I don't understand what t
is and why it calculates by the following formula:
var t = dx * distToBubble.x + dy * distToBubble.y;
?
This has little or nothing to do with programming, it is absolutely Math. So I think this question shouldn't be here, but I will answer it just for helping you out.
I don't understand what is
t
The line of movement of the bubble being fired is defined by a parametric equation, wich parameter is the variable t
why it calculates by the following formula
This is kind of complex, the book just shows the final result of the following calculation. There is a formula to calculate the distance between a point and a line. In this case the point is the center of the target bubble and the line is represented by the parametric equiation previously shown. After you solve that, you can derive that equation to find the minimum distance.
Although there is an easier way to solve this. Using dot product between the origin of the target bubble and the coordinates of the shooted bubble with the parametric function and equal it to 0 (perpendicular intersection) you cand find the value for t
.
The important point here is that the book already solved the problem for you and it is showing the final result so you can use it.
Good luck with your game!