Questions about updating my node.js game
Asked Answered
W

1

7

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?

Weisshorn answered 12/4, 2012 at 12:26 Comment(0)
M
3

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!

Methanol answered 12/4, 2012 at 16:6 Comment(4)
the article seems like a good starting point to resolving the problem, but I still didn't understand a thing from the solution :))Endue
@Endue The source of the EPIC library is clear if you understand C++. Only two files with comments (Extrapolator.h and Extrapolator.cpp) If you are not fluent in C++ I can do an effort either to explain it or to implement it.Methanol
nah it's ok. I didn't look at the source code, just read the article you pointed out. The description of the algorithm is pretty short, and I was having trouble understanding it, but I'm sure it makes sense.Endue
Thanks for your advice, I am looking into that EPIC thingy right now, and it might come in very handy.Weisshorn

© 2022 - 2024 — McMap. All rights reserved.