Object selection

I want to write code to shoot an object directly in the line of my gun. What check should I do to figure out if the object is hit?

You may use color picking, OpenGL selection buffer, raytracing or something similar. Search about selection in the forum - this question was asked many times.

Hope this helps