public bool collidesWithAny( ref Vector2 motion, out CollisionResult result )
{
result = new CollisionResult();
// fetch anything that we might collide with at our new position
var colliderBounds = bounds;
colliderBounds.x += motion.X;
colliderBounds.y += motion.Y;
var neighbors = Physics.boxcastBroadphaseExcludingSelf( this, ref colliderBounds, collidesWithLayers );
// alter the shapes position so that it is in the place it would be after movement so we can check for overlaps
var oldPosition = shape.position;
shape.position += motion;
var didCollide = false;
foreach( var neighbor in neighbors )
{
// skip triggers
if( neighbor.isTrigger )
continue;
if( collidesWith( neighbor, out result ) )
{
// hit. back off our motion and our Shape.position
motion -= result.minimumTranslationVector;
shape.position -= result.minimumTranslationVector;
didCollide = true;
}
}
// return the shapes position to where it was before the check
shape.position = oldPosition;
return didCollide;
}