Skip to content

🎮 COLLISION#

ANTIRUINS provides a simple collision system that can be used for basic collision detection.
It currently handles AABB to AABB and AABB to Circle collisions.

Note

As of now, you can find multiple edition of bump in the lib folder.
bump_c2.lua is the most recent and recommended version.

Since most of these function takes the world as their first argument, you can use these function as methods of the world object.

    local item = {} -- this can be any table in your game, it could be a texture table, a player table, etc.

    bump.add(world, item, x, y, w, h)
    --is the same as
    world:add(item, x, y, w, h)

    local collision --the object it collided with.
    local dX, dY = 10, 10 -- the amount of movement you want to apply to the item.
    item.x, item.y, collision = world:move(item, dX, dY, bump.SOLID) -- world:move with return where the item actually is after the move.


function bump.newWorld(cellSize)
Creates a new world object.
cellSize define the size of each cell for grid spatial partitioning.


function bump.add(world, item, x, y, w, h)
Adds a new Box (AABB) collider to the world. Returns


function bump.addCircle(world, item, x, y, r)
Adds a new Circle collider to the world.


function bump.remove(world, item)
Removes an item from the world.


function bump.update(world, item, x, y, w, h)
Updates the position of an item.
This doesn't check for collision, but updates the rigidbody position.
w and h are optional, if you don't provide them, the item will keep its previous size.


function bump.move(world, item, x, y, response)
Moves an item to the specified position.
Response must be either bump.SOLID (default) or bump.CROSS.
Returns newX, newY, collisionObject.


function bump.check(world, item)
Checks if item is colliding with something. Returns collisionObject.


function bump.getRect(world, item)
Returns the rectangle x, y, w, h of an item.

Note

You can visualise your collider by using the draw function.

graphics.drawRect(world:getRect(item))


function bump.getCollider(world, item)
Returns the collider of an item.


function bump.getColliders(world)
Returns all colliders in the world.