Call RPC only on specific GameObject

Options
Hello. I've been "googling" for hours, but I still couldn't find answer for what I am looking for, yet I think it is pretty simple. Basicly I want to do this:
Player1 tells Player2 to call some method. This method modifies Player2's position, but Player2 has Photon Transform View, so there is no need to do some more synchronizations.
It works like this: Player1 discovers, that it is Player2, who should call this method on his local device. So Player1 tells that Player2 should do this:

GetComponent().RPC("KnockBack", PhotonTargets.All, enemyPlayer.position, strength);

But I don't really want PhotonTargets.All ... I want only this gameobject to do this method and via Photon Transform View synchronize its transform with other players.

Comments

  • Tobias
    Options
    An RPC is always called on some GameObject's PhotonView. It only affects this GameObject, no others.
    The PhotonTargets.All is basically the list of receivers (you and all other players execute the push). This does not define which objects are pushed.
  • Bondy
    Options
    Hm, then this is strange... Lets say there are 5 players in the room. Player1 is facing Player2. So when Player1 presses some key, Player2 should be knockedBack. So Player1 calls RPC like this: Player2.GetComponent<PhotonView>().RPC("KnockBack", PhotonTargets.All, Player1.transform.position, strength) . So now should only Player2 be knocked back... But what happens is, that everyone is knockedBack...If I change PhotonTargets.All to PhotonTargets.MasterClient, then if Player1 or actually anyplayer is facing any other player and presses some key, the MasterClient is knockedBack...
  • vadim
    Options
    How MasterClient could be knockedBack? Did you mean that Player2 on master client only get a call? That's expected.
    I guess you have Player2 instance on every client. Sending RPC to PhotonTargets.All will trigger call on every Player2 instance across network. Player1 or any other PhotonView object will no be affected by this call.
  • Bondy
    Options
    Ok, I've solved this problem. I was checking what player I am facing by their name and since every instance of player has the same name, all players called their own KnockedBack method. Sorry for silly question and thanks for your responses.