TERRATECH BLOG

Co-op in TerraTech - A Story

By Matt Guest, posted 3rd August 2019

We recently added Co-op Campaign to TerraTech. It's been a long and complex journey but we've arrived! Let's talk about how we got here

Going from Single Player to Multiplayer

In it's very early stages as a gameplay prototype TerraTech was always intended to be a multiplayer game. However, multiplayer games are notoriously hard to make and as the team was just one person at the time it made the most sense to start out simple and build from there. TerraTech entered Early Access and the team started to grow and the game started to evolve from it's simple, block building demo. More systems were added, more code implemented.

While the fundamental mechanics of fighting, scavenging and building lends itself perfectly to a cooperative game mode, it got to the point where the codebase wasn't able to support such an ambitious idea, at least not without a heavy rework of the underlying code.

With the ultimate goal of a Co-op Campaign game mode, first we had to figure out how multiplayer in its simplest form would work in TerraTech. The most straightforward way to do this would be a PVP mode - Enter Deathmatch! This was relatively straightforward as the core mechanics were already there, we just needed to network them together. We did this via Peer 2 Peer networking, with a host acting as the server. It was very important that multiplayer was as responsive as singleplayer, every action should happen in realtime. This led us to add client side prediction and networked damage and building. This acted as a proof-of-concept but wasn't without issues, in that the basics of playing with others was feasible, however, some of the underlying code needed work.

Friends not Foes

Building techs is core to TerraTech and is something that has to work smoothly and predictably in all cases, even multiplayer. When progressing from Deathmatch (PVP) to Co-op (PVE), we suddenly introduced the possibility of two or more players trying to attach to or detach from blocks on the same tech (or even on the same attach point on the same block!).

Our first pass at synchronising tech building over a network had the bare essentials, with players just telling each other what they'd built and no computer really checking that any of it was valid. This was adequate for Deathmatch, where two operations were unlikely to happen on the same tech at the same time, but going forward we had to add more complex solutions. For example. the system has players requesting attach and detach operations from the host who verifies these actions, and undoing any actions that were rejected by the server.

The next logical step was to get players playing together, not just fighting to the death. Our first release of Co-op Creative was very similar to Deathmatch, just with an infinite inventory. After a lot of work went into fixing block building, we were able to add basic team switching controls, the lobby browser and save and load. Finally players were able to experience the core TerraTech gameplay with others in Co-op Creative. This formed a foundation of Co-op in TerraTech that we could build on.

Co-op Enhancements

Since the Deathmatch code which Co-op Creative was built from did not support dynamically-loading or unloading world tiles, players had to stay close to their start point. To explain: the world is split into large tiles, and only a set of tiles near the player are actually created and simulated. This is necessary to keep performance and memory usage manageable, since the world in TerraTech is potentially infinite. To prevent players from reaching parts of the world which aren't simulated we added a fixed barrier which prevented players going too far.

However, having a fixed area of play went against one of the core features of TerraTech; Exploration! This was less problematic for Co-op Creative, but it would be a huge drawback for Co-op Campaign. So the next step was to support moving the simulation area and network-synchronising the loading and unloading of world tiles, and correctly synchronising any objects on those tiles.

We restrict all players to the same area so the burden on the host doesn't become excessive - the networking model we use requires the host to keep simulating any object which any player can see or might interact with.

The result is actually very similar to how it works in single player, except the tile loading is based off the average player position. In single player, the simulation area is always based off your position, so you don't see the edges!.

Mission Impossible?

Once player tethering had been implemented the next big step towards Co-op Campaign was adding missions. We moved mission spawning further out to prevent players other than the person browsing the mission board from moving into the reserved mission space and blocking it from spawning safely. The missions themselves needed tweaking too, as any logic that was based on the player being in range or doing a certain action now had to check for all players in a sensible manner.

When playing Co-op for the first time you'll notice that some blocks aren't available, mainly crafting blocks such as fabricators and refineries. This is because the scope of work required to get them working in Co-op would have a larger impact on other new features so we had to draw the line. This did highlight an opportunity for us to take a look at crafting as a whole in TerraTech and how we can improve on the existing system. As a way around the lack of crafting we added the ability to sell blocks from a brand new, Co-op exclusive, Trading Station.

So what's next for Co-op in TerraTech? Firstly, we'd like to look at how crafting works, whether that be unlocking the current blocks, or re-evaluating the whole crafting system in both Co-op modes. It's very early days when it comes to this so we will keep you posted when we've decided on a plan of action.

As for everything else, if you've got any suggestions or feedback on Co-op then please let us know! You can post to our forums here: forum.terratechgame.com or join our Discord server here: https://discord.gg/xFvQye9