Host moves client players slowly

So far everything I’ve tried breaks something else or creates another problem, so any help is appreciated.

When I run this with a host and a client, the animator performs everything properly (such as idle animation and running animation) on both systems. However when the host player inputs any movement command when the client player isn’t moving, the client model also moves with the host but much slower.

Does anyone have any diea on what the problem is? Here’s my PlayerMovement.cs:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class PlayerMovement : NetworkBehaviour
{

    private Animator anim;
    private Rigidbody2D myRigidbody;

    public float runSpeed;

    [Command]
    void CmdWalk(bool isWalking, float input_x, float input_y, float x, float y)
    {
        RpcWalk(isWalking, input_x, input_y, x, y);
    }

    [ClientRpc]
    void RpcWalk(bool isWalking, float input_x, float input_y, float x, float y)
    {
        if (isLocalPlayer)
            return;
        anim.SetBool("isWalking", isWalking);
        anim.SetFloat("x", x); //animation direction based on mouse /joystick position
        anim.SetFloat("y", y);

        if (isWalking) //if walking, translate player
        {
            //transform.position += new Vector3(input_x, input_y, 0).normalized * Time.deltaTime * runSpeed;
            myRigidbody.velocity = new Vector2(input_x, input_y).normalized * runSpeed;
        }
        else
        {
            myRigidbody.velocity = new Vector2(0, 0);
        }
    }

    // Use this for initialization
    void Start () {
        anim = GetComponent<Animator>();
        myRigidbody = GetComponent<Rigidbody2D>();
       
    }
   
    // Update is called once per frame
    void Update () {
        var mousePos = Input.mousePosition;
        mousePos.x -= Screen.width / 2;
        mousePos.y -= Screen.height / 2;
        float input_x = Input.GetAxisRaw("Horizontal");
        float input_y = Input.GetAxisRaw("Vertical");

        bool isWalking = (Mathf.Abs(input_x) + Mathf.Abs(input_y)) > 0;
        bool isStat = (Mathf.Abs(input_x) + Mathf.Abs(input_y) + Mathf.Abs(mousePos.x) + Mathf.Abs(mousePos.y)) > 0;

        CmdWalk(isWalking, input_x, input_y, mousePos.x, mousePos.y);


        if (isLocalPlayer)
        {
            anim.SetBool("isWalking", isWalking);
            anim.SetFloat("x", mousePos.x); //animation direction based on mouse /joystick position
            anim.SetFloat("y", mousePos.y);

            if (isWalking) //if walking, translate player
            {
                //transform.position += new Vector3(input_x, input_y, 0).normalized * Time.deltaTime * runSpeed;
                myRigidbody.velocity = new Vector2(input_x, input_y).normalized * runSpeed;
            }
            else
            {
                myRigidbody.velocity = new Vector2(0, 0);
            }
        }
       
    }
}

well, you are sending the CMD CmdWalk in Update(), but the network is probably not sending 60+ messages a second, and your movement code on the non-local-player is then getting fewer calls, so it moves “slower”.

Thanks for replying. Umm let me rephrase that. I meant that the client player (who is not actually supposed to be moving) is slowly moving (on the host’s screen) when the host player moves. So I only want the host player to move instead of having both of them move.

Hope that clarifies it a bit more.

Not really - the “host” player has a representation on both the HOST computer and the CLIENT computer. The CLIENT probably also has its own representation on both the HOST and CLIENT, right? 2 players, 2 “avatars”, one for each player? Or are you saying that only the HOST should have an avatar that both HOST and CLIENT can see, but only the HOST can control?

Look at your Update(), you are checking if the player is local too late. You only want the object to send its position to the server if it’s a local player, as is now even if a player doesn’t have control over an object you’re still taking in input from them for it.