i am using mirror networking which is based on UNet. I can move non local objects easly by assigning their authority to the local player and move them, but i can’t assign/remove authority for other player’s in the game, therefore i can’t directly change their velocity. Any ideas how can i change other non local player’s velocity from local player ?
Well, i don’t know if this is the proper way but i have managed to solved this by sending message to server and server sending that message back to the clients. Clients can act (move in my case) upon that.
would you mind elaborating on this? I would like to port 2-4 people at a time based off the actions of the main player. for instance, sending each player to a designated starting zone when player 1 presses play.
Please read through our documentation, if you understand the basic principles then this is much easier.
Generally your player isn’t movable on someone else’s client, that’s the whole idea of authority.
I really want to port 4 players when one player starts a lobby session. right now I can only port the first player. here’s my code.
public void Teleport()
{
if (player.isServer || player.isLocalPlayer)
{
if (player.party.InParty() || allowSolo)
{
if (player.party.party.partyId % 2 == 0)
{
Debug.Log("player party id is even found instance");
if (player.isServer)
player.movement.Warp(instance.entry2.position);
Debug.Log("warping to entry 2");
}
else
{
Debug.Log("player party id is odd found instance");
if (player.isServer)
player.movement.Warp(instance.entry1.position);
Debug.Log("warping to entry 1");
}
}
}
}
[Command]
public void CmdTeleport()
{
RpcTeleport(); //This sends a message from the server to all connected clients that have THIS GameObject and tells them to execute all code inside the "RpcClientChangeColor" function.
and then i call it this way.
Teleport(); //This executes the "ChangeColor" function on the server ONLY.
}
[ClientRpc]
public void RpcTeleport()
{
Teleport(); //This executes the "ChangeColor" function on the client ONLY.
}
Player[] players = FindObjectsOfType<Player>();
foreach (Player player in players)
{
if (lobbyManager.IsPlayerOwner)
{
player.npcArenaTeleport.CmdArenaCreator();
Debug.Log("player is owner, cmdarenacreator called");
}
// do something with Escript etc
player.npcArenaTeleport.CmdTeleport();
Debug.Log("cmdteleport called on all players");
}
something is wrong tho. it normally disconnects the second player or just ports the first player. any ideas what I am doing wrong? I’ve read over the mirror documentation but I don’t think I have a firm grasp of authority assignments yet.
I finally got it to work! ok but I have a question. How come the NetworkServer.active always returns false? isn’t it initialized in the networkmanager?
to further elaborate, when I build a headless build the networkserver is never activated because it is normally activated through host/play button? so how do I do networkserver.spawn without networkserver?
It returns false on client. Returns true on server.
it returns false on the server too! I get this error if I try networkserver.spawn on a remote server. network server is not active. cannot spawn objects without a network server.
Where are you calling it from on server? And are you sure the code is being executed from server?
You should call NetworkServer.Spawn only from within a CMD.
Example:
void Start()
{
if (isLocalPlayer)
{
CmdSomeRandomCommand(); // Use NetworkServer.Spawn in that command
}
}
I am calling it when I create an instance. it returns this error SpawnObject for Arena3(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server. this is only when I host on a remote server. for some reason the instantiate doesn’t show up on any clients besides client 1 so I tried networkserver spawn but i get this error.