Categories
General

Node.js experiment: MMO Asteroids

I’ve had my eye on Node.js for a while now so I jumped at the chance to attend Remy’s excellent workshop a couple of weeks ago. Most people associate node with websockets but actually node is a hugely versatile platform capable of running powerful servers and web-apps.

That said, anyone who knows me will know that I’m fascinated by real-time multi-player games (remember my Lunar Lander trails?) so the first thing I’ve done is put together a little demo to test out the MMO capabilities of the node.js socket server. It’s a Asteroids-esque space shooter, with one rocket per person, use the cursor keys to fly, and space to fire.

Synchronisation

It’s a very early prototype, I’m still working on the system to keep all the ships in sync, so you might see some strange movement. I haven’t tested it with that many connections yet so it’ll be interesting to see how well it holds up under fire – please spread the word so I can help to test how it scales up!

There’s been some interest this week with Mozilla’s BrowserQuest (also based on node.js) and that uses a point and click to move mechanism. This is a classic way to reduce the amount of bandwidth and it gets around latency issues, as each move is just a single message to and from the server.

Dead reckoning

It’s much much harder to create a system with free movement and collisions, as all the data the server gets for each player is already out of date. I use a primitive form of ‘dead-reckoning’. As well as the position data, I also send the server the current velocity and a time stamp.

The data for each player is sent to the browser, along with the time-stamp and velocity. It’s then up to each client to smooth out that motion, and predict where each ship should be now, if the player carried on along that trajectory. Of course this is quite an inaccurate system, and I’m still refining the algorithm

Security

Any in-browser game is fundamentally hack-able. That’s why I’ve set up an ‘authoritative server’ system. Although the browser updates all the physics for the player, the server authenticates the ships movement to make sure there’s no funny business! The collision detection is performed locally and then the damage is verified and reported by the server.

Node.js

I’ve been really impressed by the performance and accessibility of node, apparently the V8 JS engine that powers it is can in some cases be 30% of the speed of native compiled C++ code. And there have been huge advantages in using the same JS code on the server and client. I’m looking forward to seeing how well it scales.

Next steps

It’s a really early demo, and I have lots more work to do, but please test out the mechanism, and let me know how the synchronisation and dead reckoning feels. There may still be the odd glitch. I’ll be keeping an eye on it over the next couple of days so I’m sure there’ll be the odd drop-out. Let me know how it works for you!

Play MMOsteroids

[UPDATE] yes, yes check the date. Full confession.

31 replies on “Node.js experiment: MMO Asteroids”

Is this really MMO? I keep finding a ‘space’ that has blank area, as if at the edge of a board. Every time I come back in from that area EVERYONE moves as one to attack me. It looks more like fancy emergent flocking behavior then real people.

In fact Im almost positive this is some how faked/emulated or filled in w/ bots. If I sit perfectly still, you’d think someone would stop and attack an easy target, but they dont they actually seem to avoid me. In addition to that, why dont I see anyone else doing the same thing?

Hi Seb,

this is awesome! I’m curious, I saw a ton of spaceships flying around, are they all real players?? I’m impressed. Also, what protocol did you use between the client and server? I’m assuming HTTP?

I think I partially answered my own question by following the browser quest link, protocol = WebSockets

I sometimes encountered giant groups of ships behaving exactly the same. Is this because of the collision detection system, or is it something that is generated when someone gets outside some ‘field’ in the game?

Hmm, this seems to happen at random times, when I’ve survived long enough. Suddenly a couple of ships start attacking solely me and surrounding me. That’s when suddenly this group starts to exist. Anyway, I’m very much enjoying the game.

They groups appear all over the map and there are no ‘real’ players left. Perhaps this happens when I lose connection to the server.

I just think it’s funny that your link at the end is called “Play MMO STEROIDS”
After all, it is asteroids on steroids.

Am correct in think this was posted on the 1st of April?

And whenever I disconnect from wifi I still get the connections counter increasing and they still fly around and shoot, still acting like there is a network connection!

I like what you did here! 😉 and If I wrong then DOH! Ignore this post!

I think its a flaw that user and AI controlled characters are not visually differentiated. At times the bot behavior really shows, undermining the believability of the system.

Guys, it’s an April Fools’ joke – open up developer tools and you’ll see no network requests, lol.

Hey, this is really interesting! Could you put up the source code somewhere?

Good & funny, could feel like everybody’s in the same stuff, then once you survived more than everybody, all the dead guys become controlled by AI and the shoot at you ! Love it ! 🙂

One thing though : It would be nice to have more inertia to be able to build speed-drift-shoot ! That would (maybe) give a chance to kill that raging mob that owns you !
Toughts ?

I see the game only for a second, then all space ship disapears. I tried it with Chrome and Firefox any hints?

thx hauke

I’ve tried with Ubuntu 10.04 and Firefox and it just gets stuck on “connecting”

LOL, took me about 10 minutes to realise. awesome idea if it was genuine though i hope someone makes it. i broke the game though. if you stay in one place a fly around in small circles, after a minute all the AI will attack at once, when this happens fly upa to the right and you will enter a big empty space with 4 fleets of AI in each corner synchronized and acting the same, you can fly in circles for as long as you want firing and never get hit

Comments are closed.