Seb Lee-Delisle

Menu

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.

This entry was posted in HTML5 Canvas, Multi-user. Bookmark the permalink.

31 Responses to Node.js experiment: MMO Asteroids

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current day month ye@r *