Real-time NODEJS data transfer

To practice, I am trying to develop a multiplayer game. I am using NODEJS and HTML5 canvas. I use Socket.io to exchange data between client and server

I would like to know how to optimize client-server data transfer.

INFO

  • The player is constantly moving and I have to update the player's position every 1000/60ms (60fps).

  • Player movements:

    vecX = mouse.x - player.x;
    vecY = mouse.y - player.y;
    vec = Math.sqrt(vecX*vecX + vecY*vecY);

    dx = vecX/vec;
    dy = vecY/vec;

    player.x += dx*player.speed;
    player.y += dy*player.speed;

      

  • What have I tried?

First try:

  • The client sends the mouse position to the server for every mouse movement.

  • Server keeps mouse position

  • The server updates the players' position (for each mouse position) every 1000/60 ms and returns it to every player who has a position on the screen (only part of the map is displayed on the screen).

-> Problem: Lagging a lot.

2nd Try:

  • The client sends dx and dy to the server for every mouse movement (not mouse position).

  • The server extracts these dx and dy to each player.

  • The client moves each player along them dx and dy.

  • The server moves each player over it dx and dy (just refreshing the data on the server side).

  • The server receives the position of the players every 100ms (corrective position).

-> Problem: unsynchronized data

+3
javascript node.js html5 socket.io transmission


source to share


No one has answered this question yet

Check out similar questions:

13
Massively Multiplayer JavaScript Game Built with Node.JS - Dividers
4
Multiplayer game motion sync
3
ever higher latency in node.js multiplayer html5 game
2
Big game lag in node.js and socket.io (real time)
1
Real-time multiplayer game - regional broadcast
1
Multiplayer Game - Sync Ball
1
Making real time game socket.io pong faster
0
Real Time Graphics with Node.JS
0
Html5 multiplayer game with nodeJS and Socket.io rotation not working
0
Easeljs - smooth animation over socket.io and nodejs



All Articles
Loading...
X
Show
Funny
Dev
Pics