Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Questions about updating my node.js game

Questions about updating my node.js game

Problem

I am making a little game using node.js for the server and a .js file embedded in a HTML5 canvas for clients. The players each have and object they can move around with the arrow keys.

Now I have made 2 different ways of Updating the game, one was sending the new position of the player everytime it changes. It worked but my server had to process around 60 x/y pairs a second(the update rate of the client is 30/sec and there were 2 players moving non-stop). The second method was to only send new position and speed/direction of the player's object when they change their direction speed, so basically on the other clients the movement of the player was interpolated using the direction/speed from the last update. My server only had to process very few x/y7speed/direction packets, however my clients experienced a little lag when the packets arrived since the interpolated position was often a little bit away from the actual position written in the packet.

Now my questions is: Which method would you recommend? And how should I make my lag compensation for either method?

Problem courtesy of: Wingblade

Solution

If you have Low Latency, interpolate from the position in which the object is drawn up the new position. In low latency it does not represent much of a difference.

If you have high latency, you can implement a kind of EPIC. http://www.mindcontrol.org/~hplus/epic/

You can also check how it is done in Browser-Quest. https://github.com/mozilla/BrowserQuest

Good luck!

Solution courtesy of: rromeroar

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Questions about updating my node.js game

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×