Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- A module responsible for checking for collisions between 2 elements ---
- --- Math functions ---
- local abs = math.abs
- --- Local functions ---
- local function absVector(vector)
- return Vector2.new(abs(vector.X), abs(vector.Y))
- end
- local function getVectors(element)
- return element.AbsolutePosition, element.AbsoluteSize
- end
- --- Returned function ---
- return function(element1, element2)
- local pos1, size1 = getVectors(element1)
- local pos2, size2 = getVectors(element2)
- local rangeVector = (size1 + size2) / 2
- local distance = absVector(pos1 - pos2)
- if (distance.X <= rangeVector.X) and (distance.Y <= rangeVector.Y) then
- return true
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment