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

I need to cast a ray in 2D space for bullet collision detection, but the Ray.Intersects method requires a BoundingBox which uses vector3's not vector2's. My question is should I just ignore the Z value and pretend it's a vector2? Raycasting is already slow enough so I think having calculations done in an unnecessary 3rd deminsion should be eliminated even if the value is just 0, but I don't know.

So should I implement my own raycasting system maybe using Bresenham's line algorithm which is for 2 dimensions or should I go the cheap way and make a bounding box a bounding plane?

share|improve this question
It's worth pointing out that Bresenham's line algorithm is definitely not the same thing as a Ray-AABB intersection test. – Andrew Russell Aug 19 '12 at 6:26
up vote 0 down vote accepted

Yes, you can just use Vector3's where the z-value is 0.

In geometry, any 2D point also exists in the 3rd dimension. In a 2D game, everything could be represented with Vector3s where the z-values are all identical. Often in a 2D game, you use the Z value as the depth, to draw a tree in the background (low Z value) or the main character in the foreground (higher Z value).

share|improve this answer

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.