Page 54 - MSDN Magazine, October 2017
P. 54
GAME DEVELOPMENT
Multiplayer Networked
Physics for Web Game
Development
Gary Weiss
Webgameshaveashoddyreputation.Well-writtengamesare available on high-end game consoles, and for computers equipped with modern graphics processors. Even mobile gaming has come a long way since the canonical “Snake.” But Web games, like Rodney Dangerfield, get no respect. That said, recent advances in modern browsers have the potential to bring quality gaming experiences to the browser. The most important technology in this respect is WebGL, which brings direct access to hardware-accelerated graphics.
In this article, I’ll investigate Web gaming from a specific point of view: implementation of a simple multiplayer networked-physics game. This exercise investigates which technologies and game development tools are available for the task, and stress tests modern
browsers for networking performance, computation efficiency, and rendering. This article can be viewed as a small investigation that is part of a much larger theme: Can a professional game stu- dio really write a high-end game in a browser?
The source code for the game is freely available at bit.ly/2toc4h4, and the game is playable online at sprocketleague.lance.gg.
The Game
The game I’ll model involves cars driving around in a stadium. There’s a large ball in the stadium that can be bounced into the goals. This concept is inspired by “Rocket League,” a popular e-sports title by Psyonix. Therefore, the game is assembled from the following objects: an arena (including the goals), cars and a ball, as you can see in Figure 1. The player can move the car forward or in reverse and turn the wheels.
The Architecture of the Game
The game implementation uses the authoritative server model, whereby each client forwards user inputs to a central server. Clients won’t wait for the network before they apply the inputs locally; rather, the clients will perform what’s commonly referred to as client-side prediction. This technique allows the client to continue running the game logic and game physics. The catch, of course, is that when updates to positions and velocities are broadcast from the authoritative server, each client must make its own incremental corrections so that the game preserves a smooth visual experience.
This article discusses:
• Game architecture
• Client-server communication
• Game logic
• Client-side prediction
• Web game challenges Technologies discussed:
WebGL, A-Frame, Cannon.js, Lance.gg
Code download available at:
bit.ly/2toc4h4
50 msdn magazine