Colliders.lua
Colliders is a library that helps manage custom collisions in LunaLua, making custom behaviour much easier!
It supports native collisions between players, NPCs and animations, 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. |
Point
Values
| Point.x | The x value of the point collider |
|---|---|
| Point.y | The y value of the point collider |
Functions
| Point:Draw | colour | |
|---|---|---|
| Draws the collider to the screen with the specified RGBA colour. If no colour is supplied, the default will be used. | nil | number
A 4-byte hexadecimal code supplying the colour to draw with. The default is 0x0099FF99. |
| Point:Debug | boolean | |
| Tags the collider for debug drawing. | nil | boolean
Tag or untag the collider. |
Box
Values
| Box.x | The x value of the top left of the box collider |
|---|---|
| Box.y | The y value of the top left of the box collider |
| Box.width | The width of the box collider |
| Box.height | The height of the box collider |
Functions
| Box:Draw | colour | |
|---|---|---|
| Draws the collider to the screen with the specified RGBA colour. If no colour is supplied, the default will be used. | nil | number
A 4-byte hexadecimal code supplying the colour to draw with. The default is 0xFF000099. |
| Box:Debug | boolean | |
| Tags the collider for debug drawing. | nil | boolean
Tag or untag the collider. |
Circle
Values
| Circle.x | The x value of the centre of the circle collider |
|---|---|
| Circle.y | The y value of the centre of the circle collider |
| Circle.radius | The radius of the circle collider |
Functions
| Circle:Draw | colour | |
|---|---|---|
| Draws the collider to the screen with the specified RGBA colour. If no colour is supplied, the default will be used. | nil | number
A 4-byte hexadecimal code supplying the colour to draw with. The default is 0xFF00FF99. |
| Circle:Debug | boolean | |
| Tags the collider for debug drawing. | nil | boolean
Tag or untag the collider. |
Tri
Values
| Tri.x | The x value of the triangle collider |
|---|---|
| Tri.y | The y value of the triangle collider |
| Tri.v | The vertex list of the triangle collider |
Functions
| Tri:Draw | colour | ||
|---|---|---|---|
| Draws the collider to the screen with the specified RGBA colour. If no colour is supplied, the default will be used. | nil | number
A 4-byte hexadecimal code supplying the colour to draw with. The default is 0x00FF0099. | |
| Tri:Debug | boolean | ||
| Tags the collider for debug drawing. | nil | boolean
Tag or untag the collider. | |
| Tri:Rotate | angle | ||
| Rotates the collider clockwise by the specified number of degrees. | nil | number
Angle to rotate in degrees. | |
| Tri:Translate | x | y | |
| Translates the collider by the specified amount with respect to its position. This will change the origin of the triangle for scaling and rotating. | nil | number
X coordinate to translate by. |
number
Y coordinate to translate by. |
| Tri:Scale | factor | ||
| Scales the collider by the specified scale factor. | nil | number
Scale factor to resize the collider by. |
Poly
Values
| Poly.x | The x value of the polygon collider |
|---|---|
| Poly.y | The y value of the polygon collider |
| Poly.tris | The triangle list of the polygon collider, generated from a vertex list |
Functions
| Poly:Draw | colour | ||
|---|---|---|---|
| Draws the collider to the screen with the specified RGBA colour. If no colour is supplied, the default will be used. | nil | number
A 4-byte hexadecimal code supplying the colour to draw with. The default is 0x0000FF99. | |
| Poly:Debug | boolean | ||
| Tags the collider for debug drawing. | nil | boolean
Tag or untag the collider. | |
| Poly:Rotate | angle | ||
| Rotates the collider clockwise by the specified number of degrees. | nil | number
Angle to rotate in degrees. | |
| Poly:Translate | x | y | |
| Translates the collider by the specified amount with respect to its position. This will change the origin of the triangle for scaling and rotating. | nil | number
X coordinate to translate by. |
number
Y coordinate to translate by. |
| Poly:Scale | factor | ||
| Scales the collider by the specified scale factor. | nil | number
Scale factor to resize the collider by. |
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/Animation/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/Animation/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/Animation/Box/Circle
The first object to test against. Box and Circle objects will not use a speed modifier. |
NPC/Player/Animation/Box/Circle
The second object to test against. Box and Circle objects will not use a speed modifier. | ||
| bounce | object1 | object2 | |||
| Determines if the first object has just bounced on the second object. The second return value will be true if the first object is a spinjumping player. Box and Circle colliders cannot be used as the first object. | boolean,boolean | NPC/Player/Animation
The first object to test against. |
NPC/Player/Animation/Box/Circle
The second object to test against. | ||
| bounceResponse | object | height | |||
| Causes the object to "bounce" upwards as if they had just jumped on an enemy. | nil | NPC/Player/Animation
The object to bounce |
number:optional
An optional bounce height modifier. By default, this will be the value of the jumpheightBounce() function. | ||
| slash | player | object | |||
| Determines if the given player has performed a sword slash and hit the object. Will return false if the player is not Link. | boolean | Player
The player to test the slash. |
NPC/Player/Animation/Box/Circle
The object to test against. | ||
| tail | player | object | |||
| Determines if the given player has performed a tanooki tail spin and hit the object. Will return false if the player is not wearing a tanooki or racoon suit. | boolean | Player
The player to test the tail spin. |
NPC/Player/Animation/Box/Circle
The object to test against. | ||
| tongue | player | object | |||
| Determines if the given player has performed a Yoshi tongue attack and hit the object. Will return false if the player is not riding a Yoshi. | boolean | Player
The player to test the tongue. |
NPC/Player/Animation/Box/Circle
The object to test against. |