A simple 2D collision system for axis-aligned bounding boxes.
- Tunneling - No matter the speed of an object it will hit anything it collides with, provided the dimensions of the objects is >= 1.
- Slide, Pass, Touch, Bounce behaviors when resolving collisions.
import 'package:thump/thump.dart';
void main() {
final Object block = Object();
final Object man = Object();
final World world = World(1024, 1024);
world.add(block, AABB.xywh(x: 64, y: 16, width: 16, height: 16));
world.add(man, AABB.xywh(x: 47, y: 16, width: 16, height: 16));
MoveResult result = world.move(man, 2, 0);
print(result.collisions.length);
}- Store objects in quadtree.
- Create a union AABB around the starting point and ending point.
- Query quadtree with the union to find potential collisions.
- Move the object <= 1 units (Nyquist frequency) at a time checking against potential collisions and resolving behaviors.
- Create infastructure to run all benchmarks.
- Instead of using a union AABB to calculate potential collisions, use a convex hull around starting and ending AABB.
- Sort potential collisions based on their distance to the starting point.
- Have a private AABB that is mutable to avoid generating garbage.
- Make potentials come back as a mini quadtree
- Divide large Move()'s into smaller moves
The API was inspired by bump.lua. That is an excellent physics engine and much more impressive than this one. This is a simplified equivalent that I implemented when really wanted it for Dart.