Lot's to talk about in this post! Been a lack of action lately, but the shooting wasn't as easy as I thought.
3:00 PM (AEST), December 9th, 2021
It's been a short while since my last post, but here we are with something to finally talk about on the blog! The main struggle of this latest build was achieving shooting over the network. See, I thought it would be easy to implement as it is probably the most popular feature people want to achieve when making a hobby multiplayer project. Boy, was I wrong!
The first technique I attempted for shooting over the network was hosting the actual shooting event on the server, which did work, though with a minor flaw. This technique worked by requesting a bullet from an Object Pool spawned on the server, getting that bullet ready for fire and then doing the actual fire event on the server and pushing the position updates of that bullet to all the clients. Networking these bullets did work as intended, but clients had severe latency issues; Initial firing delays, despawning was out of sync, and bullets would fire before they had finished resetting. So the research began to find a better solution.
After the previous attempts of getting shooting to work for my multiplayer game, I decided it was time to rest my mind and play Metroid Dread (Amazing, by the way). As usual, after playing a well-made game like Metroid Dread, my game developer mind started to race again, and I was ready to tackle shooting over the network once more. I decided it was time to look at it from a different angle and instead spent some time reading a variety of blogs and technical design documents. For example, one of my first finds was Valve's "Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization" page, which is a long name but was great, and a very interesting read. After skimming the valve documentation, I continued my search and came across what would become the most important find of my research, and that was a small blog about an indie developer named Paul Marsh, containing six words that blew my mind.
"Sync the action, not the result" was a small section of Paul Marsh's "Synchronizing player bullets...?" blog post of May 29th 2021. As soon as I read the title of this section, it clicked in my head exactly what he meant, and I instantly felt stupid that I never thought of it myself, but hey, that's the fun of programming.
The concept of syncing the action instead of the results of said action is quite simple. Instead of spawning and accessing the Bullets from an Object Pool located on the server, this technique has the Bullets present on each client locally and simply tells the server it wants to fire one. The client essentially says to the server: "Oh Hey, I'm gonna fire my gun now, if that's okay?", the server confirms this event and tells all the connected clients: "Hey Everyone, Player 1 is firing the gun now!" which alerts those clients that it's time to shoot the bullet from Player 1's representation in their scene. The end result of this implementation, while still silently out of sync, is a much cleaner and polished looking shooting experience perfect for the kind of game I am creating.
Paul Marsh's Blog was a great read, full of interesting posts about his development journey through MLAPI. I'll be coming back to this blog with my future MLAPI problems for sure!
Check it out: https://pauliom.medium.com/synchronizing-player-bullets-48223d5c9ad7
Lastly, let's quickly talk about some of the other changes in this build, which mostly involves inventory and item changes. However, these changes were important for completing the bare requirements for building the Murder In The Dark Prototype, hopefully coming up real soon!
The changes to this weeks build (other than the shooting, of course) are the following:
Same as the previous build, there is a new prototype available for anyone reading this post. Consider giving the game a try, and let me know what you think! The contact button at the top of the page has my social links and email, so don't be afraid to reach out and tell me all about the bugs! Thank You!