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;
}

Answers

  • Can you send us a project?
  • stanchion said:

    Can you send us a project?

    Yeah,this is the project.You can download from there.
    Link : https://pan.baidu.com/s/1i4DgFa9 Password: sdxu
  • Do you have instructions to play and see the issue?
  • stanchion said:

    Do you have instructions to play and see the issue?

    the Unity Version is 5.6.1,First you need to host a Photon Server,
    and start loadbalancing server.
    and set the Master server address is your photon server address, and package to Exe, then you can play.

  • stanchion said:

    Do you have instructions to play and see the issue?

    the main problem is that in the client side move is instantly, but in the server side the movement has a little bit of latency, I just want to know why .
  • What scene am I testing?
Sign In or Register to comment.