Hello everyone,
I am currently working on a FPS game
I finished working on the physic engine and now i want to set up the multiplayer
I’ve read a lot of topics about networking in fast paced games, but the examples that i have seen do not completely allow me to start into the subject with the necessary knowledge
Let me first explain my physic engine :
Each player’s inputs are stored in an array, for example when the player press the up arrow (keycode = 37) then array[37] = true, else false
I have a main loop that handle players movements physics and which is invoked each frame with requestanimationframe()
In this loop i verify if array[37] is true, then i add a certain value to Z axis, multiplied by the time elapsed with clock.getDelta()
So the distance traveled by each player in 1sec will be the same and independent of the refresh rate of their screen
Now the fun part : How to calcultate this, server side ?
I want the server to be authoritative, i just want to get the players inputs and let the server decides of the new positions of the players
Of course i want to implement client side prediction so the client doesn’t have to wait for the server to give them their new coordinates
First of all, do i have to send the key pressed event to the server, or each time the main loop (client side) detect a key is pressed in the variable array ?
Does the server also has to execute a loop which verify the key pressed in order to apply physics ?
But with this option i need to choose an interval for the loop, which will be different from the client
And what if the player pressed on W and 0,1 sec after on S, if he has 500ms ping, typically the server will know the player has pressed on W and only 500 ms after on S, so during 500ms, the loop will increase its Z axis value because array[W] will be true …
And in fact, that won’t match with the client game state and it’s gonna be unplayable
Do you have any ideas, examples, documentation on a similar game ?
I want to implement it in such way that its gonna be performant, efficient and scalable…
I’m using node js & socket.io to achieve this
Thank you guys !