0
\$\begingroup\$

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?

\$\endgroup\$
1
  • \$\begingroup\$ It's worth pointing out that Bresenham's line algorithm is definitely not the same thing as a Ray-AABB intersection test. \$\endgroup\$ Aug 19 '12 at 6:26
0
\$\begingroup\$

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).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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