Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I have a sprite, drawn like this:

spriteBatch.Draw(levelCannons[i].texture, levelCannons[i].position, null, alpha, levelCannons[i].rotation, Vector2.Zero, scale, SpriteEffects.None, 0);

Picture levelCannon as being a laser beam that goes across the entire screen. I need to see if my 3d model intersects with the screen space inhabited by the sprite. I managed to dig up Viewport.Unproject, but that seems to only be useful when dealing with a single point in 2d space, rather than an area. What can I do in my case?

share|improve this question
up vote 2 down vote accepted

Did you mean Viewport.Unproject? This method is used to covert a point from screen space into world space. You can follow the instructions on the MSDN page on how to convert a 2D screen space point into two separate 3D points that form a ray going into the screen.

From what I understand, you have a 2D line going across the screen and want to see what 3D objects are intersected by that line, like this?

enter image description here

I think what you can do is use Viewport.Unproject four times: on the left side of the screen for the far and near plane, then the right side of the screen for the far and near plane (really you only need three of these points). With these points you can create a Plane which you should use with your collision detection to see which objects fall on that plane.

share|improve this answer
Yes, I edited the question to fix that mistake. This should do nicely. – Fibericon Sep 7 '12 at 16:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.