Colliders.lua
Colliders is a library that helps manage custom collisions in LunaLua, making custom behaviour much easier!
It supports native collisions between players and NPCs, as well as custom Box and Circle colliders to be constructed.
Installation
Place the file colliders.lua into the LuaScriptsLib folder.
How to use
To enable the Colliders library for a specific level, add this line to lunadll.lua:
local colliders = loadAPI("colliders");
This will load the Colliders API.
Example
local colliders = loadAPI("colliders");
function onLoop()
for k,v in pairs(npcs()) do
if (colliders.collide(player, v)) then
v:kill();
end
end
end
This will kill any NPC that touches the player (but may not stop them from killing the player too!)
Documentation
Classes
These are classes contained within this library
Vector
Values
| Vector.x | The x value of the vector |
|---|---|
| Vector.y | The y value of the vector |
| Vector.magnitude | The magnitude value of the vector |
Functions
| Vector.dot | vector1 | vector2 | |
|---|---|---|---|
| Calculates the dot product between two vectors | number | Vector
The first vector. |
Vector
The second vector. |
| Vector:dot | vector | ||
| Calculates the dot product between the vector and another vector | number | Vector
The other vector. | |
| Vector:normalise | |||
| Calculates the normalised vector (can also be spelled "normalize") | |||
| Vector.add | vector1 | vector2 | |
| Adds two vectors together (can also use the notation "a + b") | Vector | Vector
The first vector. |
Vector
The second vector. |
| Vector:add | vector | ||
| Adds the vector to another vector | Vector | Vector
The other vector. | |
| Vector.subtract | vector1 | vector2 | |
| Subtracts one vector from another vector (can also use the notation "a - b") | Vector | Vector
The first vector. |
Vector
The second vector. |
| Vector:subtract | vector | ||
| Subtracts another vector from the vector | Vector | Vector
The other vector. | |
| Vector.mul | vector | scalar | |
| Multiplies the vector by a constant (can also use the notation "v * c") | Vector | Vector
The vector. |
number
The scalar. |
| Vector:mul | scalar | ||
| Multiplies the vector by a scalar | Vector | number
The scalar. |
Structures
| Box | x | y | width | height |
|---|---|---|---|---|
| number
The X coordinate of the top-left corner of the collider. |
number
The Y coordinate of the top-left corner of the collider. |
number
The width of the collider. |
number
The height of the collider. | |
| Circle | x | y | radius | |
| number
The X coordinate of the centre of the collider. |
number
The Y coordinate of the centre of the collider. |
number
The radius of the collider. |
External Use Functions
These are functions you will need to use the library
| Box | x | y | width | height | |
|---|---|---|---|---|---|
| Creates a Box collider. | Box | number
The X coordinate of the top-left corner of the collider. |
number
The Y coordinate of the top-left corner of the collider. |
number
The width of the collider. |
number
The height of the collider. |
| Circle | x | y | radius | ||
| Creates a Circle collider. | Circle | number
The X coordinate of the centre of the collider. |
number
The Y coordinate of the centre of the collider. |
number
The radius of the collider. | |
| getHitbox | object | ||||
| Gets the Box or Circle collider associated with the given object. | Box/Circle | NPC/Player/Box/Circle
The object to get the collider for. Box and Circle objects will return themselves. | |||
| getSpeedHitbox | object | ||||
| Gets the Box or Circle collider associated with the given object, taking into account its movement speed. | Box/Circle | NPC/Player/Box/Circle
The object to get the collider for. Box and Circle objects will return themselves with no speed modifier. | |||
| collide | object1 | object2 | |||
| Determines if two objects are touching. | boolean | NPC/Player/Box/Circle
The first object to test against. |
NPC/Player/Box/Circle
The second object to test against. | ||
| speedCollide | object1 | object2 | |||
| Determines if two objects are touching, taking into account their movement speed. | boolean | NPC/Player/Box/Circle
The first object to test against. Box and Circle objects will not use a speed modifier. |
NPC/Player/Box/Circle
The second object to test against. Box and Circle objects will not use a speed modifier. |