here some article :
http://compsci.ca/v3/viewtopic.php?t=14897
but i dont know how to write this code in love2D,
any help would be appreciated
(my english is bad,sry for thats
![Glee ^^](./images/smilies/ms-glee.png)
Code: Select all
function distance(x1, y1, x2, y2)
return d = math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
end
distance_between_circles = distance(circle_1_x, circle_1_y, circle_2_x, circle_2_y)
if distance_between_circles - (circle_1_radius + circle_2_radius) < 0 then
--The circles collided/overlap!
end
Not that simple. You're talking about a static intersection test, there are also continous collision tests that calculate the exact time of impact. Especially with moving circle vs aabb and triangles the code becomes quite hairy.Jasoco wrote:It's simple. Just check that the distance from the center of circle A to the distance from the center of circle B minus the radius of both circles is less than zero. [/code]
Right. The complexity of this test depends on what kind of interpolation you want to use. If you're willing to use linear interpolation, you can fix one of the bodies at the origin and calculate the velocity of the other one in the first one's inertial frame of reference (so circle A is at (0,0) with velocity (0,0) and all the information about position and movement is in circle B's attributes). Then you can do some simple tests that involve more linear algebra than I want to type right now to determine whether B passes through the fixed circle A. Once you know any time at which they intersect it is trivial to find the time at which they start intersecting with a binary search.ivan wrote:there are also continous collision tests that calculate the exact time of impact.
I doubt your game needs to have perfect precision, but if you want you can use a representation for numbers that can hold arbitrary expressions and evaluate them only when it needs to compare them.ivan wrote:-Floating point precision in a computer is not infinately accurate
To solve a situation like this you could do something like sorting the collisions by time, simulating the earliest collision, and recalculating the results for nearby bodies (where "nearby" is "any of the quadtree nodes that either of the two colliding bodies could have moved into or will now move into").ivan wrote:-You can't make a program (at least a REALTIME program) that moves all shapes simultaneously. That is, there is always an order in which the shapes are going to be moved/updated. Imagine 3 equal-sized circles (A, B and C) moving towards the same point (which is an equal distance between all 3 of them) at the same speed. Which collision pair are you going to resolve first? A vs B, B vs C or A vs C? The results will be different depening on the order.
I agree.sharpobject wrote:most games can get by with static tests.
Nah, I just wanted to point out that collision detection in games is built on approximations and compromises.sharpobject wrote:I sincerely think you're overthinking the problem though.
Users browsing this forum: Semrush [Bot] and 0 guests