Hi. Simple game - 2 players connected by phone, control by joystick prefab
1 phone host+ client
2 phone client.
they flying on scene with rigidbody 2d, try to hit each other. I’m using server RPC call -
public class PlayerController : NetworkBehaviour
{
[SerializeField] private Joystick _joystick;
public float x, y;
[SerializeField] public Rigidbody2D _rigidbody2D;
[SerializeField] private float XfromServer, YFromServer;
public float Speed = 5f;
void Start()
{
if (IsLocalPlayer && IsClient)
{
Debug.Log("THIS IS LOCAL player!!");
_joystick = GameObject.FindGameObjectWithTag("GameController").GetComponent<Joystick>();
}
if(IsHost)
{
Debug.Log("this is host!!");
}
if (!IsLocalPlayer)
{
_joystick = GameObject.FindGameObjectWithTag("GameController").GetComponent<Joystick>();
_rigidbody2D = GetComponent<Rigidbody2D>();
}
}
public void Update()
{
if (IsLocalPlayer )
{
x = _joystick.Horizontal * Speed;
y = _joystick.Vertical * Speed;
PlayerControlServerRpc(x, y);
}
}
[ServerRpc]
private void PlayerControlServerRpc(float x, float y)
{
Debug.Log($"Server received X={x} and Y={y}");
_rigidbody2D.AddForce(new Vector3(x, y, 0));
}
}
everything seem to work fine and smooth but the client always have “input lag” example
fit joystick right, player fly right, fit joystick left need to wait about 1 sec to fly left.
All tested on different phones, and even on same 1 PC, always same issue, but host is moving of course instantly. How can I speed up clients control?