Player prefab not move in clients only host.

I’m trying to move a player on a client and it only moves on the host. I did the essentials, I added a NetworkManager, in the field player prefab I added my prefab player, the prefab has its Network Object and its NetworkTransform, and my code is the following:

[RequireComponent(typeof(InputController))]
public class SoldadoController : NetworkBehaviour
{
[SerializeField] private float velocidadDeMovimiento;
private CharacterController player;
private Animator animator;
private InputController _inputController = null;

private void Awake()
{
_inputController = GetComponent();
}
void Start()
{
player = GetComponent();
animator = GetComponent();
}

void Update()
{
Vector2 input = _inputController.MoveInput();

if(IsServer && IsLocalPlayer){
Debug.Log(“Server”);
Move(input);
}else if(IsClient && IsLocalPlayer){
Debug.Log(“Server Rpc”);
MoveServerRpc(input);
}
}

private void Move(Vector2 input){
player.Move( transform.right * input.x * velocidadDeMovimiento * Time.deltaTime);

player.Move( transform.forward * input.y * velocidadDeMovimiento * Time.deltaTime);

}

[ServerRpc]
private void MoveServerRpc(Vector2 _input){
Debug.Log(_input);
Move(_input);

}

Sorry i dont know put code

Hi.
Did you add “network transform” component to player object?
Edit: (I saw that you said added)
I really highly recommend you video of CodeMonkey’s Tutorial.

Yes Mj-kkaya I have add a networktranform.

1 Like

I would like to make a suggestion about your code.
“Vector2 input = _inputController.MoveInput();” Do not put the line at the top of update.
Put these inside of if/else statement.

For example, if you have 5 players on the stage.
For the other 4 players, the Vector2 input = _inputController.MoveInput();" line would be run unnecessarily.

Vector2 input = _inputController.MoveInput();

void Update()
{
   if(IsServer && IsLocalPlayer)
   {
      Move( _inputController.MoveInput());
   }
   else if(IsClient && IsLocalPlayer)
   {
      MoveServerRpc( _inputController.MoveInput());
   }
}

I already resolved it. I use this post. Thanks

Hi rogelioae,

I guess one solution could have been to disable the PlayerInput component on the player prefab and enabling it in the OnNetworkSpawn override if you’re the owner:

public override void OnNetworkSpawn()
{
    if (!IsOwner) return;
    GetComponent<PlayerInput>().enabled = true;
}

Was that your solution?

FYI: To put code in your post you have to click on the button Insert Code, it will open a popup where you can select the language and paste your code, here is a screenshot:

1 Like

thank for the code, i dont know as put it.