Host side have a bit of latency than Client side.

I have a problem , please help me to solve it.
Client side Movement is instantly , but the Host side has a little bit of latency , I don't Know the Reason , please tell me! Thank you!
this is the Movement Code

public override void SimulateController()
{
IOwnPlayerCommandInput input = OwnPlayerCommand.Create();
input.InputPos = tempPos;
input.InputRotateZ= gamepadDirection.x * -15;
input.Fire = Fire;
input.InputMousePos = MousePos;
entity.QueueInput(input);
}

public override void ExecuteCommand(Command command, bool resetState)
{
if(state.Dead)
{
return;
}
OwnPlayerCommand cmd = (OwnPlayerCommand)command;
if(resetState)
{
transform.position = ClampPos(cmd.Result.OutputPos);
transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, cmd.Result.OutputRotateZ);
}
else
{
transform.position = ClampPos(cmd.Input.InputPos);
transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, cmd.Input.InputRotateZ);
FireWeapon(cmd);
cmd.Result.OutputPos = ClampPos(cmd.Input.InputPos);
cmd.Result.OutputRotateZ = cmd.Input.InputRotateZ;
}
}

public Vector3 ClampPos(Vector3 CurrPos)
{
Vector3 tempPos = CurrPos; // get the struct for changes, can't do it directly.

// Limit the movement of the player within the bounds of moveArea
if (tempPos.x > moveArea.width)
tempPos.x = moveArea.width;

if (tempPos.x < moveArea.x)
tempPos.x = moveArea.x;

if (tempPos.y > moveArea.height)
tempPos.y = moveArea.height;

if (tempPos.y < moveArea.y)
tempPos.y = moveArea.y;

return tempPos;
}

Best Answer

Answers