Today we will finally be detecting a collision with SAT. We know how SAT works, we’ve built classes to work with SAT, now we can use all of this to detect a real, live collision!

Using the classes we created last time, this is quite simple. First create a shape:

var shape1:Polygon = Polygon.rectangle(530, 30, new Vector2D(270, 360));

It’s a simple polygon created using the static function of the rectangle class. Now we need another shape to collide with:

var shape2:Polygon = Polygon.rectangle(20, 50, new Vector2D(260, 350));

And now we need to test for a collision:

var data:CollisionData = Collision.testShapes(shape1, shape2);

When you run this, you should More >