Tile Engine Collision <p>Okay, so, I am making a small tile-based digging game, now I want to do collision. How would I go about doing this correctly? I know how to check if the player collides with a tile, but I don't know how to actually make the player stop when it hits a wall. </p> <p><img src="https://i.stack.imgur.com/esnzE.jpg" alt="enter image description here"></p> <p>This is the game, I got 20x20 tiles here.</p> <p>This is the code I'm using atm:</p> <pre><code> foreach (Tile tiles in allTiles) { if (ply.rect.Intersects(tiles.rect)) { if (tiles.ID != -1 &amp;&amp; tiles.ID != 1) { if (ply.X &gt; tiles.X) { Console.WriteLine("Right part."); ply.X = tiles.pos.X + 30; } if (ply.X &lt;= tiles.X) { Console.WriteLine("Left part."); ply.X = tiles.pos.X - 30; } if (ply.Y &gt; tiles.Y) { Console.WriteLine("Bottom part."); ply.Y = tiles.pos.Y + 30; } if (ply.Y &lt;= tiles.Y) { Console.WriteLine("Upper part."); ply.Y = tiles.pos.Y - 30; } } } } </code></pre>