I've been browsing for about a hour and a half orso for a solution to this problem. I did see some threads on Xbox Live Indie Development forums but the actual forums aren't loading (Have they been taken down?) And everywhere else I look I can't find an answer.
The problem I'm having is that I can't get any sort of Intersect to trigger between two BoundingBoxes. I've created a cube in 3D space and then put a box at the opposing vertices, that box seems to be fine from what I can tell in the Output. As is the camera's BoundingBox <-- For it I took the player's position and +- 1 on every axis for the min/max. I originally intended to just re-use the playerposition for both min and max but that wasn't working so I tried this but it still doesn't work.
Here's some snippets of my code.
void CheckCollision(Vector3 inPos, Vector3 inOldPos) //The idea for the inPos and
old position was that I'd reset the player's position to the old pos if there's a collision
{
if (block.collisionBox.Intersects(cam.cameraBox))
{
Debug.WriteLine("HELP"); //This doesn't trigger
}
}
The next is the Update in the main Game class.
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
CheckCollision(cam.Position, cam.comparisonVector);
base.Update(gameTime);
}
Now moving onto the Cube's class.
private void SetUpVertices()
{
vertices = new VertexPositionColor[8];
//front left bottom corner
vertices[0] = new VertexPositionColor(new Vector3(0, 0, 0), color);
//front left upper corner
vertices[1] = new VertexPositionColor(new Vector3(0, 5, 0), color);
//front right upper corner
vertices[2] = new VertexPositionColor(new Vector3(5, 5, 0), color);
//front lower right corner
vertices[3] = new VertexPositionColor(new Vector3(5, 0, 0), color);
//back left lower corner
vertices[4] = new VertexPositionColor(new Vector3(0, 0, -5), color);
//back left upper corner
vertices[5] = new VertexPositionColor(new Vector3(0, 5, -5), color);
//back right upper corner
vertices[6] = new VertexPositionColor(new Vector3(5, 5, -5), color);
//back right lower corner
vertices[7] = new VertexPositionColor(new Vector3(5, 0, -5), color);
collisionBox = new BoundingBox(vertices[0].Position, vertices[6].Position);
vBuffer = new VertexBuffer(device, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly);
vBuffer.SetData<VertexPositionColor>(vertices);
}
And finally the Camera's class.
void UpdateBoundingBox()
{
cameraBox = new BoundingBox(cameraPosition + new Vector3(-1, -1, -1), cameraPosition + new Vector3(1,1,1));
}
If you want anything else just let me know :) I appreciate any help, thanks