0
votes

So I have a 2D game involving balls (circles) colliding. I want to be able to detect if two balls will collide before it happens, and the normal vector of the collision if a collision is going to happen. Take a look at the below picture:

Determining if balls will collide

Essentially a normalized vector represented by the red arrow is what I am interested in knowing. How can I figure that out any frame most efficiently, given I know the following:

  • The blue ball has a current initial velocity
  • The ball ball is pulled down by a constant gravity
  • The green ball does not move
  • The sizes and location of both balls
1
Assuming you have a game loop that increments a time step, then at a given time, run an inner loop to simulate the time going forward out to a certain limit, and see if the balls will ever collide. The normal vector is easy - it is just a radius of the green circle, from the center to the collision point. - mbeckish

1 Answers

1
votes

Lets assume: r1 radius of green ball (x1,y1) the position of green ball r2 radius of blue ball (x2,y2) the position of blue ball

The distance between the balls is d^2 = (x2-x1)^2+(y2-y1)^2 Collision occurs when d^2 = (r1+r2)^2

The vector is just (x2-x1,y2-y1) when d=r1+r2