Advertisement

2D ColDet between two moving spheres

Started by November 24, 2002 10:37 PM
1 comment, last by AdmiralBinary 22 years, 2 months ago
I have two 2D circles, both of them moving, and I need to know where they collide (sliding would be nice, too ). Anyone know of any good tutorials to do with this?
If that''s for a 2D game (say... like Stick Soldier), you don''t really need an analytical solution for this. You can move your object by v * dt, and check if there is a collision. To check if there is a collision,

d = distance between sphere A and sphere B
rA, rB = radiuses of sphere A and sphere B

if rA + rB < d, there is no collision
if rA + rB > d, there is a collision, and the collision point is a weigthed average of both centers
P.x = CA.x + (CB.x - CA.x) * rA / (rA + rB)
P.y = CA.y + (CB.y - CA.y) * rA / (rA + rB)
where CA, CB are the center of both spheres

If rA + rB is much larger than d, it means that the spheres are overlapping a lot. In that case, you might want to move your sphere back to its initial position, and try a smaller time step.

Cédric
Advertisement
Thanx man - helped alot

This topic is closed to new replies.

Advertisement