Simple, quick, AABB framework-independent, collision system. We do rectangles only.
Bopit
only does axis-aligned bounding-box (AABB) collisions. If you need anything more complicated than that (circles, polygons, etc.) use another library.- Handles tunnelling - all items are treated as "bullets". The fact that we only use AABBs allows doing this fast.
- Strives to be fast while being economic in resources
- It's centered on detection, but it also offers some (minimal & basic) collision response
- Can also return the items that touch a point, a segment or a rectangular zone.
Bopit
is gameistic instead of realistic.
import {World, Body} from 'bopit'
const world = new World()
const body = new Body(0, 0, 10, 10)
body.add(world)
Creates a new virtual space for tracking physical interactions split into cells.
- Parameters *
cellSize
Is an optional number. It defaults to 64. It represents the size of the sides of the (squared) cells that will be used internally to provide the data. In tile based games, it's usually a multiple of the tile side size. So in a game where tiles are 32x32, cellSize will be 32, 64 or 128. In more sparse games, it can be higher.
- Returns *
- World
Queries a rectangle in the world space and will return any bodies that are within that area.
- Parameters *
x
x coordinate, Numbery
y coordinate, Numberwidth
width of the rectangle, Numberheight
height of the rectangle, Number
- Returns *
- [Body] an array of Bodies, will return an empty array if none found
Queries a single point in the world and will return any bodies under that point.
- Parameters *
x
x coordinate, Numbery
y coordinate, Number
- Returns *
- [Body] an array of Bodies, will return an empty array if none found
Queries a line through the space and will return any bodies that are on that line.
- Parameters *
x
x coordinate, Numbery
y coordinate, Number
- Returns *
- [Body] an array of Bodies, will return an empty array if none found
Creates a new physical, rectangular object that can collide with other things.
- Parameters *
x
x coordinate, Numbery
y coordinate, Numberwidth
width of the rectangle, Numberheight
height of the rectangle, Number
- Returns *
- Body
Adds the body to a world
Removes the body from the world that it is in.
Will check the collisions and update the position of the body after the collisions
- Parameters *
x
x coordinate, Numbery
y coordinate, Numberfilter
Function(body, collision, goalX, goalY)body
the body that the check has been run on.collision
the collision currently in progressgoalX
x position of where the body is headedgoalY
y position of where the body is headed
- Returns *
finalX
the final x resting spot after collisionsfinalY
the final y resting spot after collisionscollisions
all of the collision data from collisions that happened along the way
Same as move
but without changing the body. This is good for checking before moving.
Returns the distance from one body to another
Try out the example by running npm i && npm start
in the example directory and
then opening http://localhost:8080
import {World, Body} from 'bopit'
const world = new World(32)
const body = new Body(120, 120, 20, 20)
body.add(world)
const wall1 = new Body(100, 100, 400, 10, true)
wall1.add(world)
const [finalX, finalY, collisions] = body.move(body.x - 10, body.y - 10)
kikito
https://github.com/kikito/bump.lua for writing such an awesome library that I keep re-writing it in other languages.