For example you have a vehicle which has a driver and a passenger and they can do something together with the vehicle… for example change radio channel.
Or helicopter which as a pilot and the other one a gunner… but still pilot can control both.
The problem is here the authority / ownership. I want to make Commands useable on ONE OBJECT with two players.
Lets make things easier.
Example both player can change color of a cube.
How I could do this?
What I did so far. I just made bool “isControlling”. So if the client has isControlling on true so he can control the vehicle… if server has also true on the same gameobject so the server can even control the vehicle… but however… if a client has IsControlling on true on other gameobject which isn’t spawned with him after joining so I get a warning:
BTW: On clients there is no local authority checked.
So it sounds like forwarding the command. Would this not endup with many many complicated code? I am currently making a game with photon which is top down battlefield with multi crew vehicles… but I want to change over to UNet.
To make this real like your suggestion which sounds good but very complicated in the coding part.would take many time to make it possible on every vehicle… or new vehicle.
I don’t really see a way to avoid using commands. As far as I know, there is no way to share authority for one single object. You can however either
a) pack all the commands in another NetworkBehaviour (a vehicle-controller class) on your player to keep your code cleaner or
b) maybe make the vehicles seats netobjects. You request authority. Server checks if authority is not on any other client, you obtain authority, and then you sit down (now you avoid have someone else sit down)
With authority, you can call Cmds from there. Then you can add bools to your seat-class for whatever action is allowed/disallowed so you can edit that in Unity. Have one seat may drive, another one may fire etc.
This is totally possible but you have to pass throught UNET.
I did the same for a 2D platformer : some traps are placed by a player and are trigger by local action (to avoid lag in my case).
When a trap is created he is registered on a dictionnary with his netID.
When you want to trigger it you command on the server to trigger the trap with this netID. And you can do the command on your player, because you don’t touch to the Trap. The netID used by Unet is the same on all clients and server so it’s fine.
For your example you can imagine register vehicules in the same way. And your player can do thing locally and command the action on the server. Or if you want the server control things, you can command to the server by your player and wait the response
A schematic code is : player → CmdChangeRadio(netId) → server → vehicule[netId].RPCChangeRadio() .
I did this because fighting with this fucking authority système bored me so much (seriously ? pass authoritative permission all the time ? And in most case that doesn’t work ? … ).
Say me if it’s dangerous to do that, but i don’t think so …
@Driiades yes that’s what we meant - forwarding the command/adding a controller class.
Unfortunately its clumsy, but I think it can’t be avoided. You need to have authorities because when networking, you need to deal with asynchronity. If two separate endpoints “author” the same object(directly access/change values), they could not rely on consistency anymore.