Newbie Question about RPC

Hello,
Im trying to learn more about RPCs and I have a question about a problem I have.
I have two players and one enemy npc, the npc should lookAt the player that is shooting on it.
For testing, I simulate the shooting with hitting key I (Player 1 is shooting) and key O (Player 2 is shooting).
When I shoot on the enemy using the server, the rotation of the enemy is showing up correctly on the client.
But when I try it on the client, the server doesnt show the new rotation of the enemy and I dont understand why.

Here is my code:

var direction_player1 : Transform;
var direction_player2 : Transform;

function Update ()
{	
	networkView.RPC ("target_player", RPCMode.AllBuffered);	
}

@RPC
function target_player()
{

	if(Input.GetKey(KeyCode.I))
	{
	transform.LookAt(direction_player1);
	}

	if(Input.GetKey(KeyCode.O))
	{
	transform.LookAt(direction_player2);
	}

}

The script is attached to the enemy gameobject and also has a networkview applied.
Im using Reliable Delta Compressed and its observing the gameobject.
I tried to observe the script file instead of the gameobject, but this didnt help.

Also I tried it with a OnSerializeNetworkView function, but the behaviour was exactly the same.
Can anyone please tell me what Im doing wrong? I cant get it to work.

Im very thankfull for any kind of help/hints.

cheers

I’m not sure I understand quite what your are doing (firing a function remotely at the update frequency, which checks local keyboard input at the receiving end?). How is the network view for the npc set up? If it’s owned by the server (i.e. the server is sending updates), then it won’t allow the client to update it. Could be something like that. For an npc you might want to only allow the server to actually modify it, so the client would need to ask the server to modify, not try it directly.

In general, to help figure out whats going on you could try:

  • Running the project with full networking logging turned on to make sure you see expected messages going back and forth.
  • Duplicate your project and run both the server and client instances with the editor. That way you can inspect your objects and verify they are set up on both sides, like make sure their networkview components are set up properly. You’ll need to launch Unity from the command line with the -projectPath parameter with the two project paths.

Thanks for your reply.
I was able to solve the problem.
I used a OnSerializeNetworkView function to serialize the rotation of the npc, this worked so far.

cheers and thanks again
Zwecklos