I'm making a mobile game in which there are left/right/jump movement UI buttons. The players should be able to move with those buttons. I'm using Unity and Photon Fusion Host Mode.
The problem is, for the player in client, the movement is very weird. When I press the button, it moves 'a little bit' and then gets back to its original position.
Also, the host is controlling both, the host and client.
Since I'm getting input from the UI buttons, I've not used INetworkInput, OnInput, TryGetPlayerInput or anything else.
I'm just checking this in BeforeUpdate.
public void BeforeUpdate()
{
if(Runner.LocalPlayer == Object.InputAuthority)
{
isLocalPlayer = true;
}
}
And doing the movement in FixedUpdateNetwork
public override void FixedUpdateNetwork()
{
if(isLocalPlayer)
{
if(moveRight)
{
rb.velocity = new Vector2(3,rb.velocity.y);
}
if(moveLeft)
{
rb.velocity = new Vector2(-3,rb.velocity.y);
}
}
}
How to do player movement using UI buttons using Photon Fusion Host mode?
One more thing, the movement works well when I do the same thing in Shared Mode.
In host mode network input must be used. This is because the client runs the gameplay simulation multiple times per frame and resimulates it as well (client side prediction).
You must:
GetInputfunction of the NetworkBehaviour.Also since you are using a rigidbody make sure that your object has a NetworkRigidbody component and that the physics mode is set to
ClientPredictionin theNetworkProjectConfigFollowing the Fusion 100 Tutorial will teach you all these concepts as well.