Outline: Polygon Physics Detection Library
Posted: Wed May 25, 2022 4:00 pm
Simple physics detection library I made. It is composed of polygons and detects if the lines of two polygons intersect. That means if one polygon is fully inside another then it returns false. This can be useful for things like making sure they player is staying in bounds.
Polygons can be made with arrays of points like so.
They can be rotated, moved, and scaled.
Then you can detect collisions with them.
Everything is explained in the library next to the function.
List of functions:
OL.create.basic
OL.create.advanced
OL.collision.basic
OL.collision.advanced
OL.collision.setCustomTags
OL.collision.setTag
OL.position.set
OL.position.move
OL.position.movePoint
OL.angle.set
OL.angle.rotate
OL.angle.rotatePoint
OL.scale.set
OL.scale.change
OL.scale.changePoint
OL.draw.basic
OL.draw.advanced
OL.draw.setColorPalet
OL.draw.changeColor
Feel free to make it better and release it as your own. I don't really care what you do with this, just credit me in some small form. If anyone makes anything with this, I would love to see it.
Polygons can be made with arrays of points like so.
Code: Select all
local points = {
{x=20, y=20},
{x=40, y=20},
{x=30, y=30},
{x=30, y=40},
{x=20, y=30},
}
myPolygon = OL.create.basic(points) --now your polygon is stored in that table
Code: Select all
OL.angle.rotate(myPolygon, 5) --rotates polygon by 5 degrees
OL.position.move(myPolygon, 10, 10) --moves the polygon by 10x and 10y
OL.scale.change(myPolygon, 2) --makes the polygon twice as big
Code: Select all
OL.collision.basic(myPolygon, anotherPolygon) --returns true if touching and false if not.
List of functions:
OL.create.basic
OL.create.advanced
OL.collision.basic
OL.collision.advanced
OL.collision.setCustomTags
OL.collision.setTag
OL.position.set
OL.position.move
OL.position.movePoint
OL.angle.set
OL.angle.rotate
OL.angle.rotatePoint
OL.scale.set
OL.scale.change
OL.scale.changePoint
OL.draw.basic
OL.draw.advanced
OL.draw.setColorPalet
OL.draw.changeColor
Feel free to make it better and release it as your own. I don't really care what you do with this, just credit me in some small form. If anyone makes anything with this, I would love to see it.