• Hiding lag in multiplayer games
    2 replies, posted
I've been a bit short-sighted lately, being so caught up in programming and shooting for dumb goals. Whenever I get like this I feel like I'm moving 100 miles per hour, most days fly by and everything else tends to get neglected. Fragsurf is coming along nicely, but it's been very taxing as well. I could ponder for a while about the implications of being a manic programmer, but I'll save that kinda stuff for my personal blog. Before taking on this project, I had minimal amount of experience with multiplayer programming. I've always used Lidgren, and basically just send byte arrays back and forth containing a tag and some data, then delegating the data accordingly. I've created a system based on Source Engine's networking, essentially it allows me to extend an entity class, add some properties (identifier:value) to a collection, and whenever a property is is changed, its new value is broadcasted to the client's copy of that entity. The benefit of this system is that only delta updates are broadcasted, meaning if a single value changes, then only a single value is networked and processed. Further inspired by Source Engine, I've implemented client prediction, reconciliation, and lag compensation, all based on this article here. These techniques seemed daunting at first. I sorta knew about them, and how they're suppose to work, but I tend to get confused when it comes to the actual implementation, and it's a little scary to just dive right into the code, even though that's probably the most efficient way to learn, and master, the implementations. Lag compensation was surprisingly easy. My implementation is still quite basic, but I was able to get it going in about an hour, and I already have ideas on how to make it work with complex animations and hitboxes and whatnot. The only thing I can't figure out, is how I'm going to implement slow moving projectiles, i.e. arrows from a bow. It works by rewinding the state of the game to the same frame the client was on when he fired his gun. Because the server's simulation is always ahead of the client, this essentially lets the server see what the client was seeing during that frame in the past, and is able to determine whether or not the bullets actually hit anything. Red is server, green is client. 400ms latency (200 client -> server, 200 server -> client) https://streamable.com/g1cpn Here's how it looks without lag compensation: https://streamable.com/oewoo As far as prediction goes, my biggest challenge has been ensuring deterministic movement. The less deterministic the movement, the more desync the clients will experience. This will be an ongoing effort I'm sure, and I'll be fighting Unity's physics as well. To give you an example, here's a video with no reconciliation. You can see that eventually, the server's idea of the player is different than the client's. Server is red, client is green. 200-400ms fake latency https://streamable.com/zqa89 And here's how it looks with reconciliation. The client slightly falls out of sync from time and time and is gently corrected. By the end of a bunch of crazy movement, the client and server have fairly similar positions. https://streamable.com/1dmxz I have confidence in Fragsurf's netcode right now, and I hope it proves to be true. Moving forward with Fragsurf, I will work on game design type things. The core game is pretty much coded in, and it's really easy to script up new gamemodes and whatnot, but there's almost no content. I'm really shit at this type of thing, and I'm fairly certain the only way to get skilled modellers/artists/etc onboard is to show results, or potential, and that's exactly what I hope to accomplish with the public test, because people want to see eye-candy, and the videos of a lowly gameplay programmer do not equate to eye-candy.
I went through the same for an old unity project I had, multiplayer was difficult and prediction keep me locked from progressing on the game itself for a long time because I couldn't end up liking my implementation. This one is looking really good!
Nice, just like everyone else who had to work on a multiplayer game I also worked on this issue. I remember using Catmull-Rom for the interpolation, it worked quite well for my game.
Sorry, you need to Log In to post a reply to this thread.