How to fix circle and rectangle overlap in collision response?
Since in the digital world a real collision almost never happens, we will
always have a situation where the "colliding" ball overlap the rectangle.
How to put back ball in situation where it collide perfectly with the
rectangle without overlap?
Suppose that rectangle is axis-aligned.
I would solve this problem with a posteriori approach (in two dimensions).
In short I have to solve this equation for t:
((x - t * v.x) - a(t))^2 + ((y - t * v.y) - b(t))^2 = r^2
Where:
(x, y) is the center of the ball (v.x, v.y) is its velocity. a(t) and b(t)
are functions that return the x and y coordinates of the point where the
ball and the rectangle collide (when the ball is at (x - t * v.x, y - t *
v.y) position.
Recently I solved a similar problem for collisions between balls, but now
I don't know how to calculate a and b functions.
No comments:
Post a Comment