Difference between revisions of "DistanceBasedCollision"
(Changed a few things) |
m (EPIC FAIL... typed in "bu" instead of "by") |
||
Line 2: | Line 2: | ||
It checks if the distance of one object to the other is less than the sum of their radii(plural of radius.) | It checks if the distance of one object to the other is less than the sum of their radii(plural of radius.) | ||
− | Variable Definitions : ax, ay = circleA's coordinates; bx, by = circleB's coordinates;ar, br = circleA's, and circleB's radii, respectively | + | Variable Definitions : ax, ay = circleA's coordinates; bx, by = circleB's coordinates; ar, br = circleA's, and circleB's radii, respectively |
<source lang="lua"> | <source lang="lua"> | ||
− | function checkCircularCollision(ax, ay, bx, | + | function checkCircularCollision(ax, ay, bx, by, ar, br) |
local dx = bx - ax | local dx = bx - ax | ||
local dy = by - ay | local dy = by - ay |
Revision as of 02:27, 2 October 2012
Another way of detecting collisions. This type works perfectly with circles. It checks if the distance of one object to the other is less than the sum of their radii(plural of radius.)
Variable Definitions : ax, ay = circleA's coordinates; bx, by = circleB's coordinates; ar, br = circleA's, and circleB's radii, respectively
function checkCircularCollision(ax, ay, bx, by, ar, br)
local dx = bx - ax
local dy = by - ay
local dist = math.sqrt(dx * dx + dy * dy)
if dist < ar + br then
return true
else
return false
end
end
Contributors
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info