Watch out for Client Authority on the NetworkTransform

So the Client Authority checkbox was mentioned in the video (maybe it was the preceeding video) with regards to the Network Transform. I’d already discovered the NetworkTransform when waiting for the current rounds of videos, and had cleverly discovered that using this lets me move the balls around on both the client and the server so they’re not overlapping when I played with commands and such…

However, this backfired when I went to add player movement… Player One moved ok, even on both servers, but oddly enough Player two only moved on one of the servers… As soon as I unticked Client Authority, the balls moved as God and Nature intended them to, replicated across both viewers following mouse clicks allotted in their respective windows.

4 Likes

plz help me

how to fix the error
:pensive:
error name is : Assets\user game\script\PlayerMovement.cs(37,28): error CS1503: Argument 1: cannot convert from ‘int’ to ‘string’

and my code :
using System.Collections;
using System.Collections.Generic;
using Mirror;
using UnityEngine;
using UnityEngine.AI;

public class PlayerMovement : NetworkBehaviour
{

[SerializeField] 
private NavMeshAgent agent = null; 

private Camera mainCamera; 

[Command]
private void CmdMove(Vector3 position)
{   
	if (!NavMesh.SamplePosition(position, out NavMeshHit hit,1f, NavMesh.AllAreas )) {return;}
	agent.SetDestination(hit.position);
}

public override void OnStartAuthority()
{
	mainCamera = Camera.main;
}

[ClientCallback]
private void Update() 
{
	if (!hasAuthority) {return ;}

	if (!Input.GetMouseButtonDown(1)) {return;}

	Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

	if(!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity ))  {return;}

	CmdMove(hit.point); 
}

}

Hi There, in the screen shot, you have GetButtonDown(), which takes a string as input, but you have the int 1. In the code you copy and pasted, it has GetMouseButtonDown() which takes an int.

I think you just need to change it to GetMouseButtonDown unless you are trying to use a keyboard button.

Privacy & Terms