socket io multiplayer movement
playing around with socket io and made this so far.
its definitely not done and is quite laggy but i think its a cool start
try opening it in 2 tabs and see the movement update on both :)
Voters
Share your repls and programming experiences
playing around with socket io and made this so far.
its definitely not done and is quite laggy but i think its a cool start
Wow, it is quite laggy, how are you sending the socket.io packets?
@realTronsi yeah its really laggy, im trying to think of how i can make it more efficient. at the moment everytime anyone moves the server broadcasts every user and their position and each client goes through that broadcast and updates each element position
@rafrafraf Hmm, are you handling the physics in the server side?
@realTronsi yep, i have all the players as instances of the class Player which includes their name and x y pos.
i know how im doing it is stupid i just cant think of how else to do it, got any ideas? thanks
@rafrafraf Hmm I don't think so, I don't see a script for player movement on the server side.
@realTronsi thats cool
@rafrafraf ???
Afaik you're handling movement on the client side, which is a big no-no for these kind of applications. Instead, give each player an array for their key presses on the server side, and on a set interval, move the player. If the player releases the key, send over another message.
That way all players will move at the same speed. Since you're handling movement on the client side right now, players with powerful computers will move faster than players with slower computers.
@realTronsi im not really sure still how id handle movement server side...
@rafrafraf
On the client side do something like this:
And in the server:
I didn't write any exact code since I don't have time to do that and it's up to you to figure that out, but that's the general outline
@realTronsi thanks