View Full Version : Gun and Crosshair synchronization.
Hello all. I'm making a duck shooting game and i have drawn two gluCylinders at the bottom center of the screen to imitate a shot gun.
I have also drawn a crosshair in ortho view that follows mouse movement.
I'm having trouble making the "gun" follow the crosshair.
05-03-2003, 08:38 AM
You should learn a little about math in games. Your gun should be positioned on the line (vector) connecting crosshair and bottom of the screen. I mean it should be like that:
X (bottom of screen)
It contains some equations of line functions.
You have to use tangent. Assuming that your mouse coordinates are (0,0) in the middle of the screen at the bottom (which they aren't), let's suppose your mouse coordinates were then (30, 40), which is 30 right and 40 up. Tan(x) = opposite /adjacent, so you're tan(x) = 40/30.
The inverse tangent of (40/30) then, (tan^-1(40/30) = x) x is the angle that you need to rotate your shotgun at to get it to follow the mouse.
I think that's right. Good luck!
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.