GitHub | Documentation | Become a Patron

Timing of movement

  • Can anyone give me some advice on technical design around accepting and processing player input? I am using Unity for the client side.

    Atm I am just sending a message to the server every frame as long as a key is held down and I am just adding a value to x/y when the command arrives. Would it be better to have a short timeout between sending such messages?

    private void Update()
    	if (Input.GetKey(KeyCode.LeftArrow))
    movePlayer(client: Client, action: string)
        if (action === "L") 
            this.players[client.sessionId].x -= 0.1;

    How would one deal with movement speed server side? I was thinking I should collect the player's wanted actions like, move left, right, etc; and then in the "update" function, which is a setSimulationInterval callback, I would do the actual movement so that it is locked to some time interval (movement speed).

  • administrators

    Hi @plyoung,

    I think a better approach would be to send when the key is active. Activating the "left" command when the key is first pressed, and de-activating it when it's released. This would avoid sending too many messages per frame.

  • Ah yes, that would be much better. Thanks.

    My first time trying to create a "real time" multiplayer game. I've only done turn-based, in multiplayer games, before so I'm not quite sure about all the correct ways to approach this.