- Home /
Multiplayer game - Send player positions
I'm creating a simple multiplayer game(server authoritative) and I need to be able to send to all players all players positions
So whenever one of the player moves I do this
private void SendPositions()
{
foreach (var item in ActiveUser.activeUsers)
{
foreach (var i in ActiveUser.activeUsers)
{
Net_OnMovement om = new Net_OnMovement();
ActiveUser user = i.Value;
om.username = user.username;
Debug.Log(om.username);
om.x = user.position[0];
om.y = user.position[1];
SendClient(item.Value.channelId, item.Value.connId, om);
}
}
}
First of all I update the players position and then send all positions to all players(here you can see only the send all to all part) And on the client side when the username is equal to username of the client I move the user else I move the "otherPlayer(s)" Works perfectly when there's only one player but after connecting the other one everything is delayed a lot and unresponsive. Is there something wrong with this way of sending data? Or should I look for the error elsewhere
*Player actually starts moving immediately after pressing button but the movement is laggy and it keeps moving long after the button is released (the longer I hold the longer it keeps moving after) - which actually means that the server can't handle the pace I guess ?
Your answer
