Note that there are some explanatory texts on larger screens.

plurals
  1. PO3d Wall sliding collision
    primarykey
    data
    text
    <p>I'm working on collision for walls in my game and the way I currently have it I get stuck walking into a wall. I'm trying to make my character slide on the walls but still collide.</p> <p>My character moves off of a vector I create using the angle he is facing.</p> <p>this is my collision function:</p> <pre><code> private static bool CheckForCollisions(ref Crate c1, ref Player c2,bool direction) { 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; if (direction) c2BoundingSphere.Center += c2.position + new Vector3(c2.getPlannedDirection().X, 0, 0); else if (!direction) c2BoundingSphere.Center += c2.position + new Vector3(0, 0, c2.getPlannedDirection().Y); //c2BoundingSphere.Center += c2.position; if (c1BoundingSphere.Intersects(c2BoundingSphere)) { return true; } } } return false; } </code></pre> <p>This is my update:</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) { if (CheckForCollisions(ref crate[x, y], ref player,true)) { player.clearPlannedDirectionX(); //Console.Write(player.getPosition().X + "," + player.getPosition().Y + "," + player.getPosition().Z); //movePlayer = false; } if (CheckForCollisions(ref crate[x, y], ref player,false)) { player.clearPlannedDirectionZ(); //Console.Write(player.getPosition().X + "," + player.getPosition().Y + "," + player.getPosition().Z); //movePlayer = false; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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