I'm still working with a movement, I got a great progress, but now I need to solve this problem: whenewer player pushes W button to move forward, there is boolean changing, which triggers GameManager to send a packet to server. The problem is, even if I tap on a button very fast, it fastly sends 3-5 packets, which is too much because I keep a List of every packet sent by client and as server can't work with such a big queue, this List on a client is becoming bigger and bigger every second, which isn't good because I start to have some sort of lag between client and server.
Here's code:
PlayerController:
Code: Select all
void Update()
{
if (Input.GetAxis("Horizontal") > 0)
{
//...
//MOVE
//...
MovementDirty = true;
}
}
GameManager:
Code: Select all
void FixedUpdate()
{
if (sfs != null)
{
sfs.ProcessEvents();
if (localPlayer != null && localPlayerController != null && localPlayerController.MovementDirty)
{
ISFSObject info = new SFSObject();
//info.PutSOMEINFOHERE();
ln.AddMessage(info);
localPlayerController.MovementDirty = false;
Debug.Log("Added packet to a list");
}
if (ln.messages.Count > 0)
{
//HERE I SEND EVERY PACKET TO A SERVER, STARTING FROM A FIRST ONE
ISFSObject info = ln.messages[0].obj;
info.PutInt("id", ln.messages[0].num);
sfs.Send(new ExtensionRequest("MovePlayer", info, sfs.LastJoinedRoom));
Debug.Log("Sent");
}
messages.GetComponent<Text>().text = "Messages: " + ln.messages.Count;
}
}
When I get a response from server, I delete a message with specific id from a list.
Sometimes (often) it does even send a same message 2 or 3 times.
So the question is how to limit the amount of this packets being sent to server. Maybe some distance checkings, but how? Any ideas?