If I studying a collision detection of two balls on one dimensional. Suppose the first one in position 0 and his velocity 5 pixel each frame, and second one in position 3 and his velocity -5 pixel each frame then in the next frame, the first ball will move to position 5 and second one will jump to position -2. In this case we don't have an overlapping between them so the collision detection will fail. How can I handle this case? here a picture for explanation:
Asked
Active
Viewed 54 times
0
-
can you split the time frame to be smaller enough so the ball will go only distance of part of its radius? so collision will be detected. – Lei Yang Mar 13 '19 at 00:20
-
1@Lei's suggestion is a very common way to handle things. You can also calculate the exact time of collisions and check if it is between the last and the current frame. – Nico Schertler Mar 13 '19 at 03:08
1 Answers
0
you can estimate and check the collision:
but in your case the movement is 1D and linear so you can directly compute the time of collision easily ...
pos0 + vel0*t = pos1 + vel1*t
0 + 5*t = 3 - 5*t
10*t = 3
t = 3/10
t = 0.3
so the collision occurs after 0.3 frame ... You can also add the radius of your objects into account to improve the accuracy of the time ... If you want also the collision position it is:
pos0 + vel0*t = 0 + 5*0.3 = 1.5
pos1 + vel1*t = 3 - 5*0.3 = 1.5

Spektre
- 49,595
- 11
- 110
- 380