I want to have an authoritative server, so the user pushes (in this case) awsd and moves the character around. However, I want the server to handle the physics (No cheating and such).
This is my player controller:
if (Input.GetKey (KeyCode.A)) {
DIR = new Vector3 (-1*this.throwS, 0.0f,0.0f);
System_O.networkView.RPC("handleMove",RPCMode.All,"a",this.networkView.viewID,Speed);
}
else if (Input.GetKey (KeyCode.D)) {
DIR = new Vector3 (this.throwS, 0.0f,0.0f);
System_O.networkView.RPC("handleMove",RPCMode.All,"d",this.networkView.viewID,Speed);
}
else if (Input.GetKey (KeyCode.W)) {
System_O.networkView.RPC("handleMove",RPCMode.All,"w",this.networkView.viewID,Speed);
DIR = new Vector3 (0.0f, this.throwS,0.0f);
}
else if (Input.GetKey (KeyCode.S)) {
System_O.networkView.RPC("handleMove",RPCMode.All,"s",this.networkView.viewID,Speed);
DIR = new Vector3 (0.0f, -1*this.throwS,0.0f);
}
else{
System_O.networkView.RPC("handleMove",RPCMode.All,"0",this.networkView.viewID,Speed);
}
This is the RPC function (Note the isServer):
[RPC]
void handleMove(string c, NetworkViewID id,float spd)
{
if (Network.isServer) {
GameObject temp = NetworkView.Find (id).gameObject;
temp.networkView.viewID = Network.AllocateViewID();
//Debug.Log (id);
//Debug.Log (spd);
switch (c) {
case "w":
case "W":
temp.rigidbody.velocity = new Vector3 (0.0f, spd, 0.0f);
break;
case "a":
case "A":
temp.rigidbody.velocity = new Vector3 (-1 * spd,0.0f, 0.0f);
break;
case "s":
case "S":
temp.rigidbody.velocity = new Vector3 (0.0f, -1*spd, 0.0f);
break;
case "d":
case "D":
temp.rigidbody.velocity = new Vector3 (spd, 0.0f, 0.0f);
break;
case "0":
temp.rigidbody.velocity = new Vector3 (0.0f, 0.0f, 0.0f);
break;
}
temp.networkView.viewID = id;
}
}
So when I run it the player for the client works fine on the server players screen, but can’t move on it’s own screen. I do not want the client to handle the physics but I can’t get the client to respect the movements issued by the server.
I suspect my problem is with networkviews but I am not sure what else to do (I re-allocate the views in the server side script)
Any help would be appreciated.
Cheers,
BAT