I'm currently working on an FPS engine where I'm attempting to mimic the mechanics of CS:GO as closely as possible. I've just recently started on weapon mechanics and have been attempting to figure out exactly (well not EXACTLY…but you know what I mean) how the hitscan system in csgo works. For example csgo incorporates recoil and weapon spread, so where exactly is the ray used for hitscanning cast from? My initial thought was that it was coming from the center of the users screen, with the weapon spread value added to the screen center value before being cast.
However, after I thought about this some more and analyzed some screen capture footage, when you fire, your screen jerks to simulate recoil. Therefore on the next weapon fire (either on mouse click or immediately after the last shot for automatic weapons), would recoil not be dictated by how much your screen jerked, since you'd be casting from the center of screen?
I suppose what my goal of this post really is is to start a conversation about ways to create an FPS hitscan system which takes into account recoil and weapon spread similar to games such as counter strike, with some talking points being:
- Calculating spread based off weapon properties and ray cast from center of screen
- My thoughts on this were to store an array of offset vectors for the spread of each weapon, then use these values depending on weapon rate of fire
- Weapon recoil screen jerk/movement and whether or not this should affect weapon spread. If it should not affect spread, how would one then obtain an accurate raycast from center of screen if center of screen has been modified to show this movement?
- How to show a bullet in flight coming from the barrel of a player's weapon?
- My idea for this is to include a dummy bone on the end of each weapon's muzzle, then create a bullet object at the point of the muzzle bone and translate it to the contact point of the raycast (translated very quickly)
- How to go about delaying the hit for enough time to show a bullet in flight? Occasionally in cs you'll see a bullet in flight, but if the hitscan were accounted for immediately AND THEN you saw the bullet in flight that wouldn't make sense, so I'm guessing there is some logic that accounts for this?
- This may just be as simple as saving the hit notification, then kicking off a fast bullet translation, then registering the hit…maybe…? That may lead to some oddities where you run behind a wall but still die because you actually were shot, just before you moved behind the wall. Which happens in CS all the time but this would be due to networking/client predication.