// Return shortest position offset to resolve the collision public virtual Vector2 ResolveCollision(Collider other) { CollisionData data; if (Collide(other, out data)) { if (data.penetration != 0 && data.normal != Vector2.Zero) return data.normal * data.penetration; if (data.depth != Vector2.Zero) return new Vector2( data.depth.X < data.depth.Y ? data.depth.X : 0, data.depth.Y < data.depth.X ? data.depth.Y : 0); } return Vector2.Zero; }
public static bool Collide(Collider a, Collider b, out CollisionData data) { return a.Collide(b, out data); }
public virtual bool Collide(Collider other, out CollisionData data) { switch (other.Type) { case ColliderTypes.Rectangle: return CollideRectangle(other as RectangleCollider, out data); case ColliderTypes.Circle: return CollideCircle(other as CircleCollider, out data); case ColliderTypes.Polygon: return CollidePolygon(other as PolygonCollider, out data); default: data = new CollisionData(Vector2.Zero); return false; } }