3d WebGL Browser Game #2: Client Side Interpolation
This past week I set out to implement client side interpolation for player movement and to make progress on a first defining game mechanic. I got the basic interpolation done, but didn’t do a great job of making time to work on the first mechanic. A combination of a friend’s moving out party, a busier than usual week at my job, and just feeling all around sluggish left me falling short. That’s alright, better luck this week!
How it Works
The authoritative game server sees the world as a grid of tiles. It has no notion of players’ exact x, y and z coordinates in the 3d world. Just their current tile.
Since the game mechanics will be based around tile locations we can let clients handle the interpolation between an old and new tile positions.
The server will update your game tile location once per game tick if you’re in motion. Each client has local x, y and z coordinates for every other client. They get interpolated towards the x, y and z coordinates of the authoritative tile location inside of a mattdesl/raf-loop (a neat and tiny API around request animation frame)
Potential Issues
Right now we’re pushing all client locations to all other clients, regardless of whether or not they’re nearby. Pushing unnecessary data quickly becomes an issue when more than a handful of people are playing. We don’t have this problem yet, but we’ll lean on space partitioning when we need do.
Another issue is that right now we’re linearly interpolating clients towards the next tile. This works fine when the next tile is adjacent, but quickly breaks if, say, we start allowing clients to move two tiles in one game tick. As always, we’ll address this when it’s an issue.
What’s Next?
This week I’ll be focusing on implementing a first defining mechanic. I’ll be sitting down and thinking through the emotions and feelings that I want to invoke in order to have a good framework for experimentation.
So far I know that I want the environment and game tiles to feel important, but I’m not yet sure how that will look.
Last week I played around with clients damaging other entities by attacking their game tile rather than the actual entity. This was only “visible” by inspecting the game’s state object, and that held my imagination back a little bit. I’ll have to work on some minimal visuals for the mechanics that I’m experimenting with. Just enough to get a basic sense of how things feel.
We’re moving along!