Fundamental problem with FPS: Aiming projectiles

I thought I’d post this under “general discussion” because this really isn’t about Unreal Engine per se, but any 3D engine really.

There is a fundamental problem with first-person shooters: lining up projectiles with everything the player sees and where the player is aiming.

Let’s say you’re shooting a rocket. Simple, visible projectile, generally easy to track it’s course. Let’s say it has a smoke trail so you can see exactly the path it took.
From the player’s perspective there’s a cross-hair on the screen. For the sake of argument we’ll say this rocket has perfect precision. That means that exactly whatever pixel is in the center of the cross-hair is exactly where the rocket should hit.
But where exactly does this rocket spawn in the game world? If it were to follow an exact course to that cross-hair center, it would have to spawn from the exact center of the screen and fly directly forward. But wait, the player has a gun sitting in the corner of the screen! Visually, that rocket should be seen shooting out of that gun! But if it does that, then it won’t be lined up with the center of the cross-hair.
Worse yet, there is also the player model seen int he game world that other players can see. That player is holding a gun in their hand. If the rocket spawns anywhere other than the tip of that model, that path is going to look wrong.

So there’s actually three different locations where the projectile HAS to spawn from or else the game isn’t going to look and/or play right. How exactly do we resolve this issue?
That is the question on my mind.

How exactly does one resolve this issue? How does one make projectiles be spawned/fired from a location that both looks right to the players and doesn’t cheat them with a trajectory that doesn’t match what they were aiming at?

I’m curious how this has been handled in basically any game; how it is handled within Unreal games, and if you know of different methods of how it was handled in other titles, I’d like to know that too.

Rocket spawns at end of rocket launcher barrel, line traces and vector math will give you the required direction and angle to hit the target, you can also adjust the launcher aim via aim offset so the barrel lines up with the target at different distances.

One method is to run a line trace from the camera (center of screen) to the intended target resulting in location and distance, point “A”,
then calculate the difference in angle from the tip of the barrel to point “A” ,
depending on the distance from the player this angle maybe noticeably different from the barrels “forward vector” (think counter strike had this for years, hidden by bullet speed and muzzle flash)

You can use an “aim offset” to adjust the upper body of the character to aim the launcher on this new forward vector, lot of different ways to either calculate or use vector functions to find an acceptable solution.

All I can think of is shooting something far away and an enemy runs across your line of fire right in front of you. You’d have all your projectiles appearing to fly in a straight line but then one suddenly goes cross-ways.
If it were actually rockets, okay, guy walking that close is gonna result in a bad time anyway, but if these were plasma bolts or something like that, it would look really weird.
It sounds kind of like a “rare situation” but honestly in a fast firefight there are dozens of realistic scenarios where the same sort of thing could happen. If the player is trying to aim at something but just barely is pointed at some edge that is much further/closer than what they intend, or a target quickly running out of view, or even an invincibility powerup…
The idea of making the projectile angled to hit a particular distance is just begging for shots to go sideways because it was compensating for a close target that it never hit.

Sure it is “one solution” but it doesn’t sound like an optimal solution. Plus, are the projectiles spawning from the third-person model or the first-person model?

…how was it done in UT99? I don’t recall the plasma rifle ever having its shots lag behind the first person model, nor did they ever not look like they came from the third person gun. Especially since the alt-fire had such a distinct exact trail anyone could see, it must have been done very well. And to work on machines of the era, it must have been some relatively simple code too. (And if it wasn’t as flawless as I’m remembering, then how was it improved in subsequent titles?)

Afaik the plasma rifle simply fires in a straight line from the rifle in 3rd person. In 1st person view the plasma beam is also going in a straight line slightly offset from the center. It is lerped to the center path in the first few frames after it is fired to line up both with the 3rd person gun and the final trajectory.

So the position of the gun in 1st person view is false but you are tricked to think it is in the right spot by the muzzle effect.

Other times the recoil effect make the 1st person gun jump to the center when shooting so you don’t have to tweak the muzzle/trail effect in 1st person view

There is many ways to trick the player. The more realistic shooters tend to force you to aim from the center of the screen or hip-fire with no real accuracy.

Physically turning the gun depending on how far the target is seems like an odd solution but I guess some games have tried that too.

Hmm, took some time to look closer at classic UT. Not the results I expected.
First off, Pulse Rifle, not plasma rifle. My mistake.
And it turns out the pulse rifle isn’t quite as accurate as I had thought. It fires directly forward, but it doesn’t hit the exact center of the crosshair. But it is basically close enough for a weapon of that range to not screw up your aim in practical application. And the effect doesn’t line up exactly right with the third-person models, but it is pretty close.

In UT2K4 the link gun has a wobbly effect so it can easily disguise any effort to line up with the player’s view.

The shock rifle is also firing from a bit off center to line up with the first-person model (in both games) but it has a wide enough “beam” that it overlaps with that view center. All the other projectiles, as far as I can tell, fire from what looks good for the first-person model, but the slight inaccuracy of the projectiles doesn’t carry much importance. It is really hard to notice, but the third-person models don’t usually line up exactly with the projectiles. Effects like smoke and flash seem to actually emit from the gun (in UT2K4 and up) which disguises the very subtle fact that the actual projectile doesn’t line up.

I fired up some Halo to see how they handle the sniper effect, since there is a visible trail for sniper shots, but they can’t fudge the aim for those. Turns out that the visible trail conveniently fades out when it is particularly close to the player model. The smoke cloud and muzzle flash disguise it a bit, but a keen eye reveals that this sniper trial doesn’t actually line up with the third-person model. Pretty sneaky.

Yes there is a lot of tricks being used to avoid the precise angled trajectory if the shot were to come out of the barrel.

This has plagued me for some time as well, and I have come up with a few solutions, but none of them ideal. Especially if working with assets that others have made.

  • Turn the gun orientation slightly towards the center of the screen, so the projectiles that come out of the sockets actually follow the right path to the cross-hair.
  • Completely fake it by using only hit-scan with a very fast muzzle flash that shoots a (very fast) fake projectile, and using a hit effect that incorporates the fake projectile as well.
  • Using a big barrel for projectile weapons, and covering the shot with a lot of smoke and/or effects (think of a rocket launcher).
  • Use iron sights that actually line up with the canter of the screen (the most common solution and seemingly favored solution by most developers).
  • Use super speed so the eye can’t follow the magical path that has to be taken by a projectile fired without any of the above tricks.

What do the rest of you do? Anything different? I find this subject to be very interesting, for many reasons.

Well, I guess one other solution that hasn’t been mentioned is to do what Doom did: have no crosshair, and keep the weapon centered in the screen. Projectiles appear to spawn from the gun, and with no crosshair there is no way to know that they do or do not line up. Works especially well if the game auto-aims vertically. Still could work with a modern 3D game, as long as the third-person model actually holds the gun straight down the middle of where they are facing (you know, like trained soldiers actually do in real life.) Only problem is that guns look boring when viewed straight down the barrel, and it’s harder to tell the difference between guns.

Basement Bob’s solution is literally the solution, lol. You line trace from the camera location straight forward by a very large distance — for example, 20,000 units. The start location is the camera’s position, and the end location is calculated as CameraLocation + (CameraForwardVector * 20000). Then, you check whether the trace hit anything. If it did, you use the hit result’s impact point as the target. If it didn’t hit anything (e.g. shooting into the sky), you fall back to using the trace’s end location instead. That point (impact or trace end) becomes the target for a “Find Look At Rotation” from the weapon’s muzzle to the target location. Plug that rotation into the projectile’s spawn transform, and boom — it fires exactly where the crosshair is pointing.

Pro tip for FPS games: run a single long-distance camera line trace every tick and store the result in a variable that other systems can access. This avoids doing multiple traces per frame. You can reuse that trace to update crosshair color (like red for targets, green for friendlies), to aim projectiles, to check for pickups, and so on.