Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This looks like it should be on gamedev stack exchange, and I would recommend switching to ray tests instead of sphere.</p> <p>Anyways, If you are married to your sphere-based system, you could "push" players out of the walls instead:</p> <pre><code>private static bool CorrectCollisions(ref Crate c1, ref Player c2) { for (int i = 0; i &lt; c1.model.Meshes.Count; i++) { // Check whether the bounding boxes of the two cubes intersect. BoundingSphere c1BoundingSphere = c1.model.Meshes[i].BoundingSphere; c1BoundingSphere.Center += c1.position + new Vector3(2, 0, 2); c1BoundingSphere.Radius = c1BoundingSphere.Radius / 1.5f; for (int j = 0; j &lt; c2.model.Meshes.Count; j++) { BoundingSphere c2BoundingSphere = c2.model.Meshes[j].BoundingSphere; c2BoundingSphere.Center += c2.position; Vector3 dir=c2BoundingSphere.Center - c1BoundingSphere.Center; float center_dist_sq=dir.dot(dir); float min_dist=c2BoundingSphere.Radius+c1BoundingSphere.Radius; if (center_dist_sq &lt; min_dist*min_dist) { dir.normalize(); c2.position += dir*(min_dist-sqrt(center_dist_sq)); } } } return false; } </code></pre> <p>Then your update can look more like:</p> <pre><code>for (int x = 0; x &lt;= 29; x++) { for (int y = 0; y &lt;= 29; y++) { if (crate[x, y].getType() == 11 &amp;&amp; collisionEnabled) { CorrectCollisions(ref crate[x, y], ref player); } } } </code></pre> <p>I'm not sure what the purpose of the (2,0,2) vector, or the 2/3rds thing is... I've just ignored them to express the concept</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload