- Home /
Question by
oomeroo1999 · Jun 29, 2019 at 11:05 AM ·
animationmultiplayeranimatormultiplayer-networkingapi
Multiplayer - Host's animation stops but client's doesn't.
Hi. Here is my Update code:
private void Update()
{
if(Input.GetAxis("Vertical") != 0.0f || Input.GetAxis("Horizontal") != 0.0f)
{
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime * 4;
rotation *= Time.deltaTime * 4;
string msg = "CMOV|" + translation.ToString() + "|" + rotation.ToString() + "|" + client.number;
client.Send(msg);
}
if (Input.GetAxis("Vertical") == 0.0f)
{
kontrol = true;
stopWalking = true;
}
else
{
stopWalking = false;
sended = false;
}
if (stopWalking && kontrol && !sended)
{
client.Send("CMOV|0|0|" + client.number);
kontrol = false;
sended = true;
}
}
And here is the Walk function that both host and client calls:
public void Walk(float translation, float rotation, int who)
{
if (who == 1)
{
if(translation != 0)
{
animator1.speed = 1;
animator1.SetBool("Walk", true);
player1.transform.Translate(0, 0, translation);
}
else if(rotation == 0)
{
animator1.speed = 0;
animator1.SetBool("Walk", false);
}
if (rotation != 0)
player1.transform.Rotate(0, rotation, 0);
}
if (who == 2)
{
if (translation != 0)
{
animator2.speed = 1;
animator2.SetBool("Walk", true);
player2.transform.Translate(0, 0, translation);
}
else if(rotation == 0)
{
animator2.speed = 0;
animator2.SetBool("Walk", false);
}
if (rotation != 0)
player2.transform.Rotate(0, rotation, 0);
}
}
When I'm playing on host, there is no problem. Animation plays when I walk and stops when I stop.
But when I play the client, when I stop, there is like %50 chance it stops the animation. It's the same code, why are their reactions different ?
Comment