# XNA BoundingFrustum troubles

This topic is 2938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a 2 player 2D game and I'm trying to find the distance each player is from their respective edges of the screen. I found out about the BoundingFrustrum object and it looks like it should be able to help me out. So I'm trying

 BoundingFrustum bf = new BoundingFrustum(spriteBatchMatrix* Matrix.CreateOrthographic(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height, -10, 100)); Vector3 dir = new Vector3(0,0,1); Vector3 pos; Ray ray; Player left; Player right; int leftDist = 0; int rightDist = 0; //find which player is left and right if (!player1.IsFlipped()) { right = player2; left = player1; } else { right = player1; left = player2; } //find distance left player is from left edge of screen pos = new Vector3(left.Position.X, left.Position.Y, 0); ray = new Ray(pos, dir); while (bf.Intersects(ray) != null) { ray.Position.X = ray.Position.X - 1; leftDist++; } //find distance right player is from right edge of screen pos = new Vector3(right.Position.X, right.Position.Y, 0); ray = new Ray(pos, dir); while (bf.Intersects(ray) != null) { ray.Position.X = ray.Position.X + 1; rightDist++; } 

spriteBatchMatrix is the matrix I pass to SpriteBatch.Begin(). I'm not sure if this is the correct matrix. Probably not because leftDist and rightDist always end up as 0, even though my players' positions are in the view. I don't have any other matrices that effect my camera so I'm not sure how else I should generate the BoundingFrustum.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 13
• 30
• 9
• 16
• 12