FPS shooting accuracy

Hi,

I’ve been doing some research and found a couple of ways to implement FPS shooting mechanics. My goal is to fire a bullet from the end of the barrel of a weapon to hit the center of a crosshair in the distance. I’ve found raycasting is perfectly accurate, but that fires from the center of the screen, not the weapon. You can also raycast from the center of the screen, then spawn a bullet from the barrel aimed with force and direction toward the hitpoint of the raycast, however, that introduces problems when you don’t aim precisely at a target. For example, sniping a target at 100m with a wall 10000m behind him. If you’re aimed at the wall off his head, the zeroing of the weapon will be set so that the projectile won’t be aimed exactly at his head.

My thought was to hold an object always at the center of the screen but (arbitrary) a million units into the distance, and have the weapon always zeroed to hit it exactly. For my purposes, I -believe- it will set an appropriate zeroing to hit anything, and the bullet can spawn from the weapon, but I’m not sure if that’s the best way to handle it.

If my examples aren’t clear, let me know and I’ll provide pictures.

TL;DR: How do modern titles handle firing from a weapon but accurately hitting the center of a crosshair regardless of real distance from barrel to target?

I think the aim point needs to be in the center of the screen, otherwise it will be impossible for the player to aim accurately.

To point your gun at the object you will hit raycast from the center of the screen, return the point you will hit and then zero the weapon on this point. This can be done each frame, regardless of whether you fire.

So in your example, if the aim point is off the first ray will hit the wall rather than the person and so the weapon can be zeroed on the wall.

The attached image below is the situation in which that wouldn’t work.

In the first image, the player aims a raycast at the target’s head (red line), and fires a bullet zeroed at the head. The bullet hits exactly as intended.

However, the second image is more real world. The player leads the target’s head by a small angle/distance, because bullets are not instant. The weapon is lower and slightly to the right of the camera (assuming the player model is right-handed), thus because the player is technically aimed at a far off object in the distance while leading the target’s head, the bullet will hit lower and to the right of the head. The player may have aimed correctly for his purposes, but the bullet will not be a headshot.

How can this situation be remedied?

Thanks!

1 Like

The important thing is to do all the hit calculations using the centre of the screen aim-point, not the weapon angle. Adjusting the weapon angle should just be for looks and to give you something to animate bullets from. Doing the aiming from the weapon angle would be a horrible playing experience as it would be impossible to tell if you were going to hit anything.

Now this assumes you want to model the bullets using raycasts (as pretty much all modern titles do for instant fire, i.e. not projectile, weapons) not real physics. If you want to use real physics then I would suggest you force the player to bring the weapon scope to the centre of the screen before firing , or just allow them to miss when aiming and hip shooting in this way.

I’ve been wondering the same thing and haven’t found a good solution. I think that many current FPS or TPS games do just do the thing where you raycast from center screen to find the point and then point the gun to that and shoot the projectile. As you said, it will miss when you’re leading a target at a distance. Here’s the trick: in all the games I’ve played, shooting when the gun is at the right side of the screen is considered “shooting from the hip”, and the game automatically makes your aim random, so you don’t really notice when you miss. The player can’t tell if it’s because of the bad calculation or because the game purposefully added randomness for shooting from the hip. Most FPS’s force you to zoom to a scope or pull the gun into the center of the screen in order to be in “aiming mode”, and in that case you just shoot the projectile from the center of the screen normally without having to worry about it.

If you can’t force them to aim down the center for accuracy, you could try having the bullet go from the gun towards the center-screen ray and then at a certain distance, the bullet will gradually curve and follow the center screen ray instead of its initial trajectory. I’m not sure if other games actually do this though, because I haven’t seen it suggested anywhere.

Did anybody ever figure out how to do this? Surly forcing the player to go into aim mode is not the only way… ? I am at the same point in my project and this is the first question I have found that accurately describes the problem I’m having. Please if you found a work around(other than forcing aim mode) please let me know too!

The honest answer is that a LOT of games, even AAA ones, solve this problem the easy way: By always firing from the centre of the screen, even though the gun is lower down. It’s basically a hack, and it means some dumb stuff happens, but it works.

Doing it properly and shooting from the gun, there are cases where there is no possible way for the weapon to aim to hit what the crosshair is touching (because it’s blocked, and if it aims above the obstruction, it’ll be aiming too high).

In those cases the best you can do is something like turn the crosshair red. Or hey, show a bunch of crosshairs like I do in Scraps.