Programming is cool they said it’ll be fun they said look i don’t know who they is in this scenario but they forgot to mention that you can spend two days trying to figure out why your code isn’t working wondering if your brain is malfunctioning and just before you go Completely insane you realize that you didn’t read the documentation properly and all it takes to fix it is changing one word ah yes the joys of programming so yeah making multiplayer games kinda sucks over the last few weeks i’ve been working on re-implementing client prediction into my game and player Movement is once again nice and responsive but why was the movement unresponsive in the first place and what the heck is klein prediction well let me introduce you to the arch enemy of all game developers that are working on multiplayer games latency you’re able to watch this video right Now because youtube servers are sending the video’s data to your web browser however this doesn’t happen instantly as it takes time for that data to physically travel from youtube to your computer that travel time doesn’t really make a difference when you’re watching a video or stealing someone’s code but if you’re Building a fast-paced multiplayer game where reaction speed is critical latency will literally make your job go from easy to pure pain and suffering imagine light travel 299 million 792 458 times slower than it actually does or at one meter per second now imagine you’re standing a meter away from someone if That person took a step to the right you would only see them start to move an entire second after they actually started moving this is essentially the same problem that games face because by the time your computer is told that another player moved that information is already outdated you can probably figure Out for yourself why that would cause major problems in games like first person shooters where even a fraction of a second of delay in another player’s position could cause you to be aiming at nothing seriously when they were creating the internet who decided that latency was a good feature to add In this video though i just want to talk about movement a little delay wouldn’t make movement unresponsive on your end right you could just have every player’s computer calculate and update their own position the same way single player games do it players would still see each Other in the past but at least they would see themselves move immediately after pressing a key unfortunately this is where the second half of the problem comes in cheaters you can’t trust your players because a certain amount of them will happily exploit anything they can and often this Will ruin the experience for other players to prevent things like speed or fly hacks you need your game server to be the one calculating the movement for all players as it’s the only thing you can trust unless of course you’re an incompetent programmer in which case you can trust nothing So since the server has to handle your movement for you that means when you press the w key to move forward you have to wait for your computer to send that instruction all the way to the server then the server does the calculation updates your position and you have to Keep waiting until that update finally makes it back to your computer all of that might happen in less than a tenth of a second but when you’re at the controls even that seemingly tiny amount of delay can make the movement feel sluggish this is where client prediction Comes to save us the idea here is to have the client which is your computer and the server both calculate your movement while you’re waiting for the server to receive your input calculate the proper movement and send back the result your computer will also calculate the movement and update your position Accordingly which means that when you press a key you will move immediately then when the server eventually sends back what it determined to be your new position we have your client compare that correct position to what it had predicted for the same point in time if They match which should be the case most of the time for a non-cheating client then all is well with the world if they don’t match the position needs to be corrected but because nothing is allowed to be simple when developing a multiplayer game it’s obviously not as easy as just overwriting your current Position since your current position is predicted and therefore essentially from the future and the position from the server is technically in the past the two can’t just be compared because when you’re moving they actually should be different we’re basically dealing with multiple time streams meaning that time travel Doesn’t just happen in books and movies your computer is constantly doing it every time you play a fast-paced multiplayer game i won’t go into any more detail though because this is the point where things get even more complicated and confusing and i’d rather get back to the practical side of things Remember how at the beginning of the video i said player movement is once again nice and responsive well i lied sort of the movement is smooth and responsive on land but this is what happens when you step on a boat why remember our good friend latency yeah me neither because latency Is the enemy not our friend since the server is the one calculating the movement for the ships by the time a position update reaches your computer it’s already outdated that means that when you try to predict your movement from onboard a boat you’re doomed to fail because you’re working with a Different starting position than the server is it’s kind of like taking two calculators and punching in different numbers then adding one even though you added one to both the result will never be the same because the starting numbers were different basically you end up constantly mispredicting your position which then Triggers a correction and sometimes that correction will put you inside the ship’s collider because the ship position is outdated and then the physics system loses its mind because colliders aren’t allowed to be inside one another but then that puts you in the wrong position again so another correction is triggered immediately Afterwards and it causes a vicious cycle of violent jittering so through the power of editing you’ve been spared several more weeks of me questioning why i decided to build a multiplayer game or get into programming in the first place but i’m pleased to announce that i have successfully made predictions smooth Even on boats since my prediction works on dry non-moving land i just made the boat also not move i have this duplicate of the ship way under the water where no one will ever run into it and when you step onto the actual real moving boat both the client and the server start Using this proxy to calculate your movement you can think of it like being teleported onto the duplicate boat except visually you still see yourself moving on the real one since the proxy doesn’t move there’s no incorrect predictions to deal with except when getting on and off of boats because That’s when the system has to change where and how it’s calculating movement the way it is now the jitter is pretty noticeable when you jump off a boat but since it’s only for a moment i think a bit of smoothing should be able to hide it quite well Anyways i’m super relieved that i finally got this working but of course i’m building a multiplayer game so i need to make sure to test this with more than one player connected at a time You Video Information
This video, titled ‘Why Making Multiplayer Games SUCKS’, was uploaded by Tom Weiland on 2021-09-08 06:45:01. It has garnered 302944 views and 14016 likes. The duration of the video is 00:06:46 or 406 seconds.
I finally decided to tackle some of the more complex issues I was having with multiplayer, and this is how it went…
Next devlog: https://youtu.be/cYLnVp1ngwA Pirate game playlist: https://www.youtube.com/playlist?list=PLXkn83W0QkfmQI9lUzi–TxJaOFYIN7Q4
⎯⎯⎯⎯⎯⎯
More about client prediction & reconciliation: https://www.gabrielgambetta.com/client-side-prediction-server-reconciliation.html
Discord server: https://tomweiland.net/discord Support me on GitHub Sponsors: https://github.com/sponsors/tom-weiland Support me on Ko-fi: https://tomweiland.net/kofi GitHub: https://tomweiland.net/github Project’s Trello board: https://trello.com/b/vJwk0iwS/pirate-game Website: https://tomweiland.net/
⎯⎯⎯⎯⎯⎯
Gear & Software I Use
Developing ⮞ Engine – Unity: https://store.unity.com/#plans-individual ⮞ Code Editor – Visual Studio: https://visualstudio.microsoft.com/vs/ ⮞ 3D Modeling – Blender: https://www.blender.org/download/
Recording & Streaming ⮞ Screen Recorder – OBS Studio: https://obsproject.com/ ⮞ Camera – Panasonic G85: https://amzn.to/39P77GK ⮞ Microphone – Vision AU-PM422: https://amzn.to/2LsTIuG
Computer Parts & Peripherals ⮞ Mouse – Logitech G604: https://amzn.to/3mqUSoy ⮞ CPU – AMD Ryzen 7 2700X: https://amzn.to/3pU06K9 ⮞ GPU – GeForce GTX 1050 Ti: https://www.newegg.ca/p/N82E16814125915 ⮞ Motherboard – ASUS Prime X470-Pro: https://amzn.to/3p20h5f ⮞ SSD – Gigabyte 240GB: https://amzn.to/39UPWDQ ⮞ HDD – WD Blue 1TB: https://amzn.to/2O37EMI ⮞ RAM – 8GB x2 ⮞ Case – Fractal Design Meshify C: https://amzn.to/3q6FgHy ⮞ Power Supply – EVGA 750 GQ: https://amzn.to/2N3T3A0
Other ⮞ YT Channel Management Tool – TubeBuddy: https://www.tubebuddy.com/tomweiland ⮞ Webhosting – Bluehost: https://www.bluehost.com/track/tomweiland/
I personally use all of the above products and services, so they are genuine recommendations. Some of these links are affiliate links, which means I get paid a small commission (at no extra cost to you) if you sign up or buy through them. Thanks for supporting the channel!
⎯⎯⎯⎯⎯⎯
#LatencyIsTheEnemy #Devlog #PirateGame #GameDev #IndieDev #IndieGame #Multiplayer #GameDevelopment #Unity #Unity3D #MadeWithUnity
In this multiplayer devlog I finally decided to tackle some of the more complex problems I’ve been having with multiplayer. Latency is the enemy, and makes building multiplayer games 1000 times more painful and time consuming. While I’ve managed to get latency mitigation techniques like client prediction working on dry, non-moving land, it’s a whole other story when you’re standing on a moving boat, and this video is a summary of my experiences over the last 3 months.
⎯⎯⎯⎯⎯⎯
The music used in this video is sourced from the YouTube Audio Library and StreamBeats.