Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions about updating my node.js game

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?

like image 602
Wingblade Avatar asked Apr 12 '12 12:04

Wingblade


1 Answers

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!

like image 120
rromeroar Avatar answered Nov 11 '22 12:11

rromeroar