UNET - Prevent Local Client to receive Server Command!
Hi everyone!
Hope someone can point me in the right direction.
My goal is, that the Client A locally moves and sends his end position to the Server. The Server should send the new position to every client, but Client A should ignore the Server function call.
The idea is to prevent lags for the local player, the position should be only synced on other clients.
So far i managed that Client A sends his movement to the server. Now how can I achieve the rest? (PLS no reference to use NetworkTransform)
Thanks!
Answer by phineliner · Dec 08, 2015 at 06:13 PM
If you a re not using NetworkTransform, I assume you use ClientRpc. You could simply use the isLocalPlayer Attribute of your PlayerScript in order to ignore the received RPC. So inside your PlayerScript (which should extend NetworkBehaviour) you would have something similar to this:
[ClientRpc]
public void RpcAdjustPosition()
{
if(isLocalPlayer)
return;
//Update Position
}
I thinks that's it! Thanks!
Didn't know about the command tag "ClientRpc". I take the LocalPlayer executes it ?
As soon I get it to work, I greenlight you ;)
ClientRpc will call the respective method on all clients connected to the server. The $$anonymous$$ethod is called on the server and executed on all the clients. To only make it work on the local client, you check for "isLocalPlayer" as shown above.
See http://docs.unity3d.com/$$anonymous$$anual/UNetActions.html for more information about Commands and RPC