Sign in to follow this  

Gunsight Positioning

This topic is 4712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am continuing the development of my 3D Aeroplane game in Visual c++ 7 and DirectX 9. Okay, some of you may have read the thread I started asking how I could simulate shooting. The bullets fly now... no worries. Thanks to everyone who helped with that. However, I now have slightly different problem. I have a simple textured quad as a gun sight on the screen. This is positioned just above the front of the aircraft. When I shoot my bullets I want them to head towards the center of the gun sight. I use the gun sight x and y co-ordinates and the distance I want the bullets to fly to determine their trajectory. So, at the moment I have the bullet fly up to 500 units on the z axis from its starting position and there are very small steps made on the x and y axis to give it smooth movement to its destination point. The problem is, that because the gun sight is not at the exact point that the bullets will eventually go the bullets do not look as if they go to the centre of the sight, but off to one side or another (depending on my position). I have tested this by putting the gun sight at the exact point the bullets should go (500 z units away from the aeroplane) and this works fine. So, my thought is to do it this way:- Disable the z buffer. Then, draw the gun sight quite large at the actual farthest point away from the aircraft that the bullets will go. This will gives the illusion that the gun sight is its normal size but in reality it will be a fairly large quad. However, I am not sure about using this method as it seems to be a bit of a cheat and not a very elegant way of resolving things. What do you guys think of this idea? And have you any suggestions for a better way to do this? If you need any more info then just shout. Thanks Dave

Share this post


Link to post
Share on other sites
I have been given a hint that the problem may be resolved by keeping my gunsight as a 2D object. Then by extracting the bullets position in 2D co-ordinates I could then make it look as though the bullet is traveling to the center of the gunsight when in reality the bullet is traveling down the z axis.
However, I am still at a loss for how to do this.

Has anyone any suggestions please :-)

Thanks
Dave

Share this post


Link to post
Share on other sites
This may be the wrong way to go about it but I think I would try to set it up similar to real life. What I mean is that there are two "trajectories". One is the trajectory down the gunsight and the other is the trajectory the bullet flies. Both of these will then intersect at some distance from the airplane.

Basically the idea is since the gunsight and bullet do not start at the same point, calcualte a trajectory line for each that intersects at a desired distance from the airplane and that is the trajectory your bullet needs to follow. This will only go down the center of the gunsight if the airplane does not change its flight path at all while the bullet is flying.

Though maybe this isn't what you are asking...

Share this post


Link to post
Share on other sites
I'd pick an arbitrary point, say 100m in front of the plane along the axis of fire, and find the screen coordinates of the point. Then I'd draw the sight there as a 2D sprite with constant size.

This is basically what you say you're doing already, but the bullets will go through the sights instead of simply moving asymptotically towards them - dunno if that's what you wanted.

Another random idea is to have the sights actually be a 3D object in world space, out in front of the plane.

Share this post


Link to post
Share on other sites
I am confused about this problem.

If you are shooting bullets ideally the bullet would come from exactly your viewpoint. Like a sniper rifle more or less.

If not, the bullet should travel parallel with your sight, because if the gun is at an angle to your line of sight you will find it very difficult to hit things outside a certain range.

If you follow these rules then the bullets should look like they travel towards your target (because of perspective).
----------------

Share this post


Link to post
Share on other sites
My perspective on this was from the airplanes in WW2 like the mustang with guns in the wings, the guns were pointed in sligtly so that all bullets would cross at a specific distance from the airplane. Though you might not be using this style of airplane so the idea may not be useful at all...

Share this post


Link to post
Share on other sites

This topic is 4712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this