public override void Update() { base.Update(); //returns true if we collide witht the grid at any position if (Tank.Collider.Overlap(Tank.X, Tank.Y, CollidableTags.Wall)) { //notify the tank Tank.WallCollision = true; //extract the wallCollider from the list of colliders with the tag wallcollider GridCollider wallGridCollider = (GridCollider)Tank.Collider.CollideList(Tank.X, Tank.Y, CollidableTags.Wall)[0]; //calculate colliding tiles check start position, eg the top-left-most tile the tank could hit int leftmostTile = wallGridCollider.GridX(Tank.Collider.Left); int topmostTile = wallGridCollider.GridY(Tank.Collider.Top); //get the collision rectangles List <Rectangle> collidingRectangles = CollisionUtilites.GetCollidingRectangles(wallGridCollider, Tank, leftmostTile, topmostTile); //filter out identical rectangles created when the tile checker found multiple colliding candidates collidingRectangles = collidingRectangles.Distinct().ToList(); //reset out of all rectangles foreach (Rectangle obstacle in collidingRectangles) { Vector2 projection = CollisionUtilites.ShortestProjection(Tank, obstacle); //something smells fishy: the projection is larger than a complete tile? f**k that. if (Math.Abs(projection.X) < wallGridCollider.TileWidth && Math.Abs(projection.Y) < wallGridCollider.TileHeight) { Tank.AddPosition(projection); } } } else { Tank.WallCollision = false; } }