DistanceBasedCollision

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.)

function checkDistanceCollision(ax, ay, bx, bu, 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