Better Shooting And Re-Spawns
Hello everyone!
This is the second devlog for the prototype so any feedback is highly appreciated!
This week was spent on improving the netcode, handling client disconnects, improving how re-spawns work, and having gunplay independent of the framerate of the clients.
Player Deaths and Re-Spawns:
In a lot of games when the player loses their health, they unsurprisingly die and re-spawn at some checkpoint or something similar. The same logic also applies to multiplayer games, although the way it is done is always different. In multiplayer games, most of them try to keep the momentum of the character previous to what it was doing before dying. So say the character was jumping before dying, they will fall to the ground like a ragdoll, with the ragdoll having the same momentum before death. Another issue that multiplayer games face for re-spawns is that people can camp spawn points so that the new players are killed as soon as they are spawned. To get around this various games use various techniques.
In my case, I used distance to players and Line Of Sight (LOS) to handle re-spawns. Before I implemented this system I only relied on distance or a random spawn point to respawn the player. When playtesting with a couple of friends, I found out that the spawns were very predictable and thus people could easily find where the new player would spawn. To fix this issue I looked into calculating Line Of Sight (LOS) for the new spawn point.
The way this system works is:
- Get a list of all the players and all the spawn points in the world
- Calculate the Center of Mass of all the players. This is then used to calculate the average distance of the players from each spawn point
- Iterate through the list of Spawn Points and calculate the distance
- If the distance is greater than max visibility distance mark the spawn point as a valid spawn
- Otherwise, calculate the LOS of the spawn point to each player and see if any player is in LOS. Then mark it as a valid spawn
- Sort the valid spawns based on distance
- Pick the spawn point farthest from the Center of Mass of the players which are not in LOS
- Exact implementation details can be found here
Frame Rate Independent Shooting:
Every multiplayer game which has shooting as one of its core mechanics, need to have its shooting not based on FPS of the client. A way to do that would be to simulate shooting entirely on the server and the client just waits for the feedback. But this waiting on the server causes a noticeable delay. To fix this, the client must have its own local shooting which is not dependent on framerate.
In my case, I tried to resolve the issue by keeping track of the difference in DeltaTime between each shot. A remainder is calculated to store the lost time that frame when the weapon was fired. This lost time is added the next time the weapon is fired to calculate if any bullets were missed.
In simpler terms, imagine the client DeltaTime to be 0.5s and the weapon FireRate to be 0.2s. The gun is just fired once every DeltaTime, it will lose 1.5 bullets per frame. To fix this I calculate a shootCount
diff = 0.5 shootCount = Floor(0.5 / 0.2) shootCount = 2
Now since shootCount greater than 0 means a valid shot can be fired. So, next, the lost time is calculated as remainder
remainder = diff - shootCount * FireRate remainder = 0.5 - 2 * 0.2 remainder = 0.1
After the remainder is calculated, the next time shoot update occurs, the remainder is added to the DeltaTime to calculate the actual bullets needed this frame
diff = 0.5 + remainder diff = 0.6 shootCount = Floor(0.6 / 0.2) shootCount = 3
So in this manner, the lost bullets are eliminated. Thus, the framerate becomes independent of the client's FPS. Exact details can be found here and here.
Other changes in the updated build include a Melee Attack for Players, Ability to Pickup and Drop Weapons and also Handling Client Disconnects
These are just my methods of resolving the problems I came across. Any feedback on how these are handled in real-world scenarios will be highly appreciated! The following week's changes will include setup for a King Of The Hill kind of game mode!
See yous guys until then. Cheers!
Files
Get Third Person Shooter
Third Person Shooter
Third Person Shooter Game
Status | Prototype |
Author | Rud156 |
Genre | Shooter |
Tags | Multiplayer, Prototype |
More posts
- Character Movement and GunplayMar 29, 2021
Leave a comment
Log in with itch.io to leave a comment.