OpenGL crosshair, 3rd person, and laser beam

Hello. I'm at the point in a game I'm developing where I am ready to implement crosshairs and laser weapons in 3rd person.

I've been thinking about it for a while and figure I might as well ask this question.

Everything is rendered using a perspective view. I've read that it's typical to turn off depth testing, recalculate your MVP for an ortho view, and then draw cross hairs, and other status indicators on the screen.

What I'm wondering about is how that would work exactly in terms of "syncing" the crosshfair position and the laser beam which will come from a third person robot.

Basically, if you crosshair is in the center of the screen, then the direction vector pointing to the target would be calculated from the position and orientation of the camera view. But the laser will be coming from the robot at a different position.

Here are a few of my thoughts.

I could "trace the direction vector from the camera to target, and then draw a laser beam from the target to the laser weapon. Questions: what if there is no contact, aiming at the sky. I guess at that point, you could just fire the laser parallel to the direction from camera to target.

Any thoughts on how this type of thing might be implemented?
I could "trace the direction vector from the camera to target, and then draw a laser beam from the target to the laser weapon.


This is what I would do.

what if there is no contact, aiming at the sky.


It depends on how you want your robot to behave in that case. If this is something like laser guidance, it would make sense for it to not fire anything at all (if the laser isn't pointing at anything what is there to shoot at?)

Or if you want it to get in just the general direction... you could choose a point on the camera-target line that's an arbitrary distance away from the camera and use that as the target.
Or if you want it to get in just the general direction... you could choose a point on the camera-target line that's an arbitrary distance away from the camera and use that as the target.


I think I might do that.

Topic archived. No new replies allowed.