0
\$\begingroup\$

I am creating a 3D asteroids game. I got the bullets, asteroids, and ship all done. They work perfectly. Now I want a crosshair to display where the ship is pointing at. The crosshair will be a 2D sprite.

\$\endgroup\$
5
  • \$\begingroup\$ Do you just mean a simple overlay of a crosshair on the middle of your screen? If so, just draw a Texture2D there. \$\endgroup\$
    – DMan
    Nov 27, 2011 at 21:23
  • \$\begingroup\$ No, let me show a picture of what I mean. \$\endgroup\$ Nov 27, 2011 at 21:24
  • \$\begingroup\$ Question on your image - is your mouse pointer the crosshair? And then you just want a line drawn to it? \$\endgroup\$
    – DMan
    Nov 27, 2011 at 21:34
  • \$\begingroup\$ The line is not supposed to be drawn. \$\endgroup\$ Nov 27, 2011 at 21:38
  • \$\begingroup\$ The crosshair is not a mouse pointer. \$\endgroup\$ Nov 27, 2011 at 21:39

1 Answer 1

1
\$\begingroup\$

You could fire an invisible infinite speed bullet from you ship during every frame, and if it hits an asteroid (or the edge of the viewport/frustum), draw your cross-hair sprite at that point. The advantage of this is that you can use your already existing bullet firing, collision detection, and hit effect code, so you should have practically zero overhead effort.

If you use this approach and your collision detection code cannot handle overshooting bullets, you either have to adjust that code or use a special method to handle that bullet, although you should probably do the former.

You didn't specify, but if by "3D game" you mean a first person perspective, then you can simply draw that sprite in the middle of the screen or at the position of your mouse pointer.

\$\endgroup\$
1
  • \$\begingroup\$ I was thinking about that. I will give it a try. \$\endgroup\$ Nov 27, 2011 at 21:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .