# FPS Aiming

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

## Recommended Posts

I'm making an FPS, and I have a small question: As usual,the gun is placed at the bottom right corner of the screen,and its aiming at the center of the screen,where the crosshair is. I want to be able to always shoot exactly where the crosshair is. The bullet(rocker,whatever) will start from the tip of the gun barrel and hit the exact point. The problem is to calculate the direction of the bullet as it leaves the gun. I was thinking about using gluUnProject to find the 3D position of the fragment where the crosshair points and calculate the direction that way.But say I'm aiming at a monster,and the monster dodges the bullet,then the bullet won't end up at a point that lies inside the crosshair. I don't know if my question is clear enough,but does anyone know how FPS games do that? [Edited by - mikeman on September 26, 2004 9:55:37 AM]

##### Share on other sites
I'm not positive, but I think that a lot of games actually just make the bullets come from the center. I know UT2k4 does it with some guns, like the Link Gun, and Halo does it with the Plasma Rifle too. I think the trick to making this look right is to have the muzzle flash extend out far enough.

##### Share on other sites
Quote:
 Original post by Pogo708I'm not positive, but I think that a lot of games actually just make the bullets come from the center. I know UT2k4 does it with some guns, like the Link Gun, and Halo does it with the Plasma Rifle too. I think the trick to making this look right is to have the muzzle flash extend out far enough.

Yeah,I know that UT2004 does that with the link gun(alt mode,right?),but I think that with others the bullets do come from the barrel.

##### Share on other sites
Firstly, most actual FPSs send the object out from the center of the screen. Play q3arena demo or something, and you will notice it. It is just so fast, the player doesn't care.

But, if you are a reallll stickler...

You cannot calculate the angle unless you do some sort of ray trace to see where the first object or wall intersection is (from the crosshair).

 |                     Traced line              (intersection pt)-o-    - - - - - - - - - - - - - - - - - - - - - - - - - x |     | 90                                          -       |                                   -       |                       -     ------ | theta       -  gun  ||   - ------

Okay, so what you basically are saying is that you eventually want the rocket to intersect, at the point of contact, with the crosshair. However, the crosshair points onto infinite. So what do we do? Take the first intersection. Knowing the distance from the gun to the crosshair, and the crosshair to that intersection (think raytracing), we find theta.

theta = tan(traced_distace/gun_to_crosshair)

Knowing theta, you can launch the rocket at that angle.

Now, you said it is also at the bottom right corner. This means that the rocket must also be shot with some X angle. If you look at my drawing as top down instead of side view, you will realize that the same works for the X angel that you need.

Good luck with that. I think that it may actually be a lot more trouble than its worth, and recommend you just cheat and make it shoot from the crosshair.

##### Share on other sites
Bullets are just a particle effect. They do not come from the barrel, but rather are just "traced". Upon connection with something, the appropriate effect is created.

Sometimes bullets do have "smoke" follow them or something (think tracers in WWII or something). Thats simple a particle effect created with the bullet vector.

Bullets do not actually exist as entities, in my knowledge. Rather, they are just a vector.

##### Share on other sites
Thanks for the replies guys.I was actually using the approach you suggested(the bullets come from the center),but I was wondering if there was an easy way these games use to make that effect.This problem mainly applies to weapons like rockets or energy bolts,those that the player is able to see them moving.I was using the term "bullets" in a generic way.Visage is right,actual bullets just need to be traced.Anyway, I guess I will take the easy way and just make the bullets come out of the center.

##### Share on other sites
You could take the approach ww2 fighter planes took - they also had guns offset from the center of the plane, and a gunsight that pointed out the nose of the plane. The pilots and/or mechanics would calibrate the guns to fire such that the rounds would go 'through' the sights at the most common engagement distance. So for example, if you were usually 200' away from your target when firing, the guns would be set up to aim at a point directly in front of the sight, 200' distant. Depending on your game environment, you could do the same thing, just pick an angle that will be reasonable and fix it. The angle will almost certainly be shallow enough to be accurate over a wide range of distances.

• 21
• 15
• 9
• 17
• 13
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!