So I’m trying to create something that on theory is simple: Server spawn the object and the client control the object that’s updated on server and other clients.
However I can’t even get client control the object to update on server, I can get at maximum the client modifying his own variable. I tried RPC, trying to put Client Network Transform component at object, Network Variable, none seems work.
public NetworkVariable<Vector3> position = new NetworkVariable<Vector3>();
public Vector3 clientVector = new Vector3(0, 0, 0);
public void Move()
{
if (IsClient)
{
clientVector = RandomPos();
UpdatePosServerRpc(clientVector);
}
}
[ServerRpc]
void UpdatePosServerRpc(Vector3 cV, ClientRpcParams rpcParams = default)
{
position.Value = clientVector;
transform.position = position.Value;
}
Vector3 RandomPos()
{
//Generate random position
return new Vector3(Random.Range(-3f, 3f), 1f, Random.Range(-3f, 3f));
}
The object is spawned by server before this code happens, the server don’t happens to appear any message error.