Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

Here is what I want:

http://imageshack.us/photo/my-images/266/whatiwant.jpg/

share|improve this question
    
Do you just mean a simple overlay of a crosshair on the middle of your screen? If so, just draw a Texture2D there. –  DMan Nov 27 '11 at 21:23
    
No, let me show a picture of what I mean. –  Daniel Lopez Nov 27 '11 at 21:24
    
Question on your image - is your mouse pointer the crosshair? And then you just want a line drawn to it? –  DMan Nov 27 '11 at 21:34
    
The line is not supposed to be drawn. –  Daniel Lopez Nov 27 '11 at 21:38
    
The crosshair is not a mouse pointer. –  Daniel Lopez Nov 27 '11 at 21:39
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
I was thinking about that. I will give it a try. –  Daniel Lopez Nov 27 '11 at 21:33
add comment

Your Answer

 
discard

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.