How the hell am I supposed to add multiplayer to this game…
The last month has been all about getting the online portion of Janken Samurai up and running.
And I don’t know what I’m doing.
I used Unity’s Photon Pun system. Pretty easy to install and free for a few players, which is ideal for testing and building games for small groups of friends. Since there is no tutorial called “How to add multiplayer to this game you made up,” I was left to figure it out on my own. Taking and abstracting resources to fit my needs.
To understand the whole issue here, I’ll have to explain how the offline Janken Samurai works. Two characters choose high, mid, or low and every five seconds (when the timer hits zero) the round ends and the results play out. High beats low, mid beats high, and low beats mid. The two characters' animations trigger for the appropriate result. If player one chose high, the “attack high” animation would trigger. If the player two chose low, the “get hit low” animation would trigger. The animations require to be launched at the same time in order to sync properly on the screen.
Moving this to online seems simple enough and when I first set it up, it pretty much worked as expected. Each player spawned a character and would control that character. But when the animations would fire, the slightest internet lag (which would be nothing in a highly kinetic game where everyone is moving at all times and hit boxes can account for slight lag) would cause the animation to lag. They weren’t in sync…
But there’s more. The timer Game Object handled the players’ health and kept track of the rounds. What I didn’t understand was that anything that player two doesn’t spawn in themselves is owned by player one (or the “host”). And it turns out, player two can’t tell anything that player one owns what to do.
So when player two tells the timer it lost health on that round, the timer doesn’t listen… It can’t be changed by player two.
It was here that it took a month of research and experimentation to understand.
Only the host can alter host objects.
But the host’s objects can read any object and act accordingly.
That’s the understanding that unlocked how I could build this thing.
The host spawns every object. Player two spawns a “Player Two Controller.” It has bools that the “Host Objects” read and act accordingly. Player two isn’t telling the timer that their health went down. The timer is reading that player two lost the round and does its own math. The host then reports those results back to player two. All the animations and UI are spawned by the host and sent to player two. Player two sees the animations in sync because they were triggered at the same time on the host side.
All in sync.
And there you have it. One month of research and implementation and we have Janken Samurai Online. I begin QA this week with some friends and I’ll let you all know how it turns out and when it’s ready for release.
Do you all know this concept of “the spirit of the thing itself?” This is a concept found in Japanese Samurai philosophy. In understanding the “spirit of the thing itself” we can find mastery. This is applied to swordsmanship in that mastery requires that the practitioner understand the sword is an instrument of death. It is a killing machine. Only in treating it as such can one obtain mastery.
I feel like with this online feature, Janken Samurai is finally the spirit of itself. I took this idea of Rock/Paper/Scissors and Samurai and forced it into a single-player, offline context. I like how it came out. But, to me, the spirit of this idea is pure person versus person, Rock/Paper/Scissors with some cool minimalist pixel art and animation. And it’s finally come to fruition.
Talk to you soon and thanks so much for reading and supporting and following me on this journey.
-Andrew