Show HN: An online 2D MMO game, written in Rust and JavaScript (polyfight.io)

171 points by altanis ↗ HN
I made a game (https://polyfight.io/) which revolves around a player (a tank) leveling up and upgrading by killing shapes and other tanks (partially inspired by https://diep.io). It has a bunch of features, a vast number of tanks, an inbuilt chatting system, clans to make teams with your friends, a colour scheme maker, controllable sandboxes which can be public or private, a last man standing gamemode, and an inbuilt 1v1 system with its own ELO rankings and a global leaderboard. The game has a few players right now, and I'd hope to spread the joy players have with this game to people here, as well as any critiques people have about the game. Exploits/gray hat hacking is warmly welcomed, as I strive to make sure my game is secure and hard to script/bot in.

102 comments

[ 3.1 ms ] story [ 179 ms ] thread
Seems like I got killed by a glitch that teleported me off screen and then marked me as "killed by Unknown"
Something similar for me as well. Played for about 10 minutes and had it happen a few times - I'd be in a fight or killing some shapes, then it would rocket me across the screen and say someone killed me. The "kill cam" would have the person who killed me somewhere quite far a way, and I never saw any bullets coming from that direction.
Same. I was having a lot of fun playing it otherwise!
Hey sorry, overnight there was performance degradation which made the server run very slow (~100MSPT). I restarted the server for a temporary fix and will fix it sometime today.
add a X button to close that huge black info box took me a while to realize i had to press ESC
There should be an X button. It's probably a CSS issue; what are the dimensions of your screen?
let's just say it's HUGE.
Very cool, reminiscent of agar.io :)
It's a really cool technical achievement but if I were you I'd put in a lot of effort to distinguish yourself from diep.io because at first glance they are identical.
(comment deleted)
Of course, I have a bunch of new features in mind to make it different from Diep.io when initially playing.
Nothing happens. I click play, it says already connected. I wait, nothing happens. I join a lobby, it puts me in the same scenario.
(comment deleted)
I think a clientside fingerprint implementation I made was faulty, I'll rework it. Sorry.
Can you tell us about your implementation?

What Rust libraries did you use, what are you using for state management, etc.?

I used Axum for the websocket server, MySQL for the database, and the glicko2 crate for elo management. Those are the only 3 that come to mind, I didn't use any libraries/engines for the game itself.
>...the glicko2 crate for elo management

That's kind of funny. When this project said it had elo rankings, I had the thought, "it's a shame they're using elo when there are better options." It seems like you are already using one of those better options!

Other than where elo is used for historical reasons, about the only other reason I can think to use it in a new project is as a placeholder until you do something better. It's great as a placeholder since it is so easy to implement.

[flagged]
(comment deleted)
Looks impressive. Like some others, I'm getting the bug that says "You are already connected" when I try to play.

That said, this is still good work, especially considering your experience and age (I checked out your 2D physics library on github and I found the trailer on youtube).

One suggestion: As someone in the game industry, I personally wouldn't label it an MMO as it doesn't include many of the features, particularly the "massive" part of MMO, that is usually associated with that term. The work is already impressive enough, you don't need to give it a label that could open it to criticism.

Otherwise, this is solid work. If you're aiming for a career in the game industry eventually, it's a good foundation to build on.

Hey, thanks! You're right, I should've probably labeled it as a multi-player game, not an MMO. The connection issue you faced was because of a (probably) faulty clientside fingerprint implementation I made; your fingerprint probably collided with others. I'll rework it in a few hours.
I suggest you use the WebTransport datagram API for your netcode, now that it's supported by the latest version of all major browsers (except Safari). WebSockets suffer from the typical head-of-line blocking issues inherent to TCP, which makes it a suboptimal fit for latency sensitive applications like multiplayer games, where you only care about the most recent state.
I wouldn't suggest WebTransport unless/until Safari gets support. Instead you can use WebRTC DataChannel today for UDP in all browsers. Also, WebTransport doesn't support direct P2P connections but WebRTC does.

I have ported Quake III to use DataChannel and it works great (once all the WebRTC boilerplate is in place). You can test it here: https://thelongestyard.link/ Once you click the multiplayer link you will get a URL with your server name, which others can visit to join your server instantly.

That is absolutely fantastic. Instant mayhem! Thank you for this.
Isn't WebTransport supposed to get P2P via QUIC?
I think there is an intention to add P2P to WebTransport someday. But I wouldn't hold my breath.
Most underrated comment, and what a blast from the past.

Back then Quake 3 would require 3d accelerators and now we can play it in the browser... and some person on HN just casually "ported it". Awesome!

What's the technology there? Do you run it on WASM?

Thanks! Yes, it's ioquake3 compiled to wasm with Emscripten, and definitely still uses 3D accelerators via WebGL. Quake III is GPL of course and the code is here: https://github.com/jdarpinian/ioq3

In addition to WebRTC multiplayer and a bunch of random improvements I added web gamepad API support as well as touch controls. Yeah, touch controls, because half of everyone is browsing on their phone and I don't think you can really call it a proper web port if it doesn't work on phones. Touch controls for Quake III were a challenge but I think I have something that's fun to use. I'm interested to hear if it works for people.

I'm also experimenting with a port of Cave Story (the classic 2D indie platformer) with touch controls for mobile: https://thelongestyard.link/cave-story/

WebRTC is complicated; there are many more edge cases compared to websockets. Off the top of my head, I know I'd need to run a TURN server for people behind symmetrical NAT or CGNAT networks, which would be a pain. WebSockets are much more accessible for everyone. In the future I'll investigate UDP protocols, but its likely I'll always use TCP for web games.
Yes, WebRTC is complicated. But you only need a TURN server for the P2P case. If you are using it in a client-server mode like WebSockets then there is no need for a TURN server, and connection establishment should be significantly simpler. And if you don't need the audio/video stuff then you can ignore that complexity as well. (Although voice chat or even video could be a very cool and differentiating feature for a multiplayer game.)
Damn, very nice indeed... Of course I got pwned before I could even get my hands on the right keys. Q3A and Quake TF mod are definitely happy memories.
I thought MMORPGs preferred TCP.
You typically want a mix of UDP and TCP (or sometimes a weird TCP-like monstrosity rebuilt on top of UDP).

Taking great care to design your data streams to be self-correcting (e.g. transfer a world location where characters are going towards instead of which direction they are heading) can go a long way towards saving a ton of synching headaches, and enables very efficient networking.

One-off events go over the TCP-like channel, but constant streaming data that naturally self-correct over time, like the example above, can benefit from being on the UDP channel.

> or sometimes a weird TCP-like monstrosity rebuilt on top of UDP

Like QUIC?

If some packet loss is not problematic, UDP is used. Often for players positions.

That's also how some speed hacks are made possible.

Have you shipped a multiplayer game yourself?
I like the idea of UDP, but protocols like WebTransport aren't 100% supported and are still relatively new compared to websockets. But you're right, using UDP would be a less latent approach and clientside prediction can account for any lost packets.
Partially inspired? That’s literally a diep.io clone. Not that that’s necessarily bad, sometimes it’s easier to clone an existing game you like when learning a new game engine/language. But you should own it.
(comment deleted)
The base game is inspired from Diep.io with extensive features already to differentiate it, but you're right the base game is still essentially Diep.io. The game is still relatively new and I haven't implemented all my ideas yet, but when I'm done the base game mechanics will be completely different.
buggy as hell. die for no reason
(comment deleted)
Sorry, the game server degraded overnight. I've restarted the server as a temporary fix and will investigate today.
(comment deleted)
Why does it ask to select a Google account?
There are some features in-game which I don't want abused by bots (creating sandboxes for instance). There's also a 1v1 system which needs a Google account to associate your rankings with. Other than those two sections, you are able to play FFAs and join other people's sandboxes without a Google account.
I think you should implement client-side prediction, it feels very laggy.

https://developer.valvesoftware.com/wiki/Prediction

There already is. The lag you were experiencing was likely from the game server degrading; did you check what the MSPT of the server was when you were playing? (It was listed at the bottom near your ping.)
How can I play the game, if I just get killed within seconds?
Seconded. The death report says I died after 2 seconds, but I actually have no chance at all to do anything, to control my tank, to even discover if the WSAD control works.

Also on Firefox the FPS meter says 40 FPS, but visually the game (the interface rather, I was unable to play) is clearly not smooth, clearly below stable 24 FPS.

Hey sorry, there was performance degradation overnight which made the game server super slow. It should be better right now.
Can't play. No player icon, random movement, death within seconds.
(comment deleted)
Hey sorry, there was performance degradation overnight which made the game server super slow. It should be better right now.
I'm unable to test this - I spawn, teleport, and then die.

I'm currently enjoying more relaxed MMO settings using threeJS libraries with multiplayer built in:

https://summer-afternoon.vlucendo.com/

This was great! Me and another player were just exploring this, and I had fun finding all of the secrets. Well done :)
It's one of the most beautiful WebGL games I've seen in a while.
Hey sorry, there was performance degradation overnight which made the game server super slow. It should be better right now.
...and which libraries are those?
Looks fun, but not an MMO in any common use of the term I’ve ever seen. In modern gaming especially a lobby system is antithetical to the concept of an MMO.
Yeah, I should've labeled it as a multi-player game instead.
I have no idea how to play. I spawn, don't see myself, the background is moving (off the edge of the map?) and I die
(comment deleted)
Hey sorry, there was performance degradation overnight which made the game server super slow. It should be better right now.
I spawn in, there is nothing on screen (no tank or player entity), 2 seconds later it says I died by someone
(comment deleted)
Hey sorry, there was performance degradation overnight which made the game server super slow. It should be better right now.
It's unplayable at the moment. I can't control my shape and I'm instantly killed in a few seconds. M1, Chrome latest.
Hey, sorry about that; there was some performance degradation overnight which caused the game server to run very slowly. I restarted the server to temporarily fix it, I'll look into it today.
No doubt it was great when you announced it 7 hours ago, but its already fallen to abuse :(
(comment deleted)
I don't think it's abuse, but just server degradation from 50 players playing for hours. I restarted the server and it's better, I'll fix the degradation later today.
Reading these comments it seems you're suffering from success
Yeah, I didn't actually expect this many people to play. I've ran benches locally of 100 bots playing together, and the game server ran at a decent 5-7 MSPT. I didn't run the benchmark for hours though, so I never got performance degradation. I'll run the bench for a few hours today and inspect why performance degrades.