Making Projectiles Spawn on a socket

I am currently trying to solve a problem with creating how guns would work in my game.

Guns in this game will spawn projectiles that have bullet drop and travel speed that will work based on models of real bullets, i.e. accounting for everything accurately besides simulated wind drag.

What I’m trying to wrap my head around here is how to make the bullet spawn on the muzzle socket of the gun, and how to make the center of the screen or cross-hair the vector in which the gun shoots.

Iron-sights are going to be a thing, however hip fire will be also. Attaching it to the socket would then put a lot of burden on the animation if I am thinking about this correctly in my head. hip fire should be inaccurate, with wobble and bobbing of the animation, not just based on an out of line spawn location that would shoot at an odd angle.

I need help wrapping my head around how to resolve these two states and making the gun still seem accurate.

If it helps, the distance these projectiles should travel is anywhere between point blank and 1000 meters.

We have looked at and experimented with the First Person Shooter template and what it is doing seems way off from what we want. It’d probably work without bullet speed / drop but adding that in kind of breaks it accuracy wise.

Currently just decided that we need a new perspective on where to start, and we think the muzzle thing may be our best shot - but we weren’t able to get that working at all. Any advice is appreciated greatly :slight_smile:

For the most part, FPS games will shoot projectiles from the camera location when it’s a hit scan weapon and then just play effects from the muzzle. This will ensure the greatest amount of accuracy when it comes to hitting the location that the player is aiming it and most people never know the difference.

However, sometimes with projectiles that aren’t hit scan (ie. they last more than one frame and travel at some discrete velocity) they will fire projectiles from the muzzle location. Usually these projectiles have some amount of homing on them to help hit targets in the center of the screen.

Can’t say which is best for your game, as it’s a case by case basis. Either way, there are precedents set in other games. Take a close look at CoD, TF2, Halo, Battlefield, etc and you should be able to reverse engineer what’s going on.

I’ve done all that - the original CoD was laser beam no travel time, the most recent BF is from the shoulder, doesn’t coincide with the camera or the muzzle of the gun - has travel time - their gun doesn’t clip walls etc for example. I wanna say halo 2 was instant.

Out of all of those games BF4 has the closest to right feeling gunplay. Halo was the most competitive game I’ve ever seen. CoD I just can’t speak much to because it stopped being a shooter right around the time they had perks and nukes and such. Never really looked at it after that and not going to drop money on them if I can avoid it.

I appreciate your input but, I don’t feel like I’ve gotten a clear understanding of it yet and neither of those options really fits for what I’m trying to do.

BF4 allows you to sight the guns to different distances on the fly - How is that achieved? Just by lowering the vector angle a set amount?

Looking at one weapon isn’t going to give you the full picture of how a game handles projectile spawning. Often times, it’s on a per weapon basis.

BF4 allows you to sight the guns to
different distances on the fly - How
is that achieved? Just by lowering the
vector angle a set amount?

Assuming you’re questioning the 3rd person implementation? For 1st person, they probably just fire the projectile from the camera location. In 3rd person, they might calculate a new spawn rotation every frame based on a raycast from the camera. Like, they adjust the projectile rotation to aim towards whatever the raycast from the camera is hitting. Not positive that’s how it’s done, but that might be a good start.

Don’t be afraid to cheat :slight_smile: The player probably won’t notice.