Search Unity

Third Party Photon animation on client

Discussion in 'Multiplayer' started by jplegris, Apr 8, 2014.

  1. jplegris

    jplegris

    Joined:
    Nov 16, 2013
    Posts:
    9
    Hi,

    my current problem goes like this.
    1- I currently get a random character to spawn on the server.(editor(Player1) and in client(Player2))

    2- When i instantiate my players i enable my PlayerAnimate and Texture flip script.

    now the players are spawning correctly and are animating perfectly but on their own client.
    In editor Player1 is good but Player2 just move bu doesn't animate.


    My spawning code:

    Code (csharp):
    1. void SpawnMyPlayer(){
    2.    
    3.         randomPlayer.Add (myPlayerWhite);
    4.         randomPlayer.Add (myPlayerRed);
    5.         randomPlayer.Add (myPlayerBlue);
    6.  
    7.         int randomPlayerIndex = UnityEngine.Random.Range (0, randomPlayer.Count);
    8.         Debug.Log (randomPlayer);
    9.         // Declare l'instance de chaque character
    10.         if (randomPlayerIndex == 0) {
    11.  
    12.                         GameObject MyPlayerGO = (GameObject)PhotonNetwork.Instantiate ("MyPlayer", Vector3.zero, Quaternion.identity, 0);
    13.        
    14.                         ((MonoBehaviour)MyPlayerGO.gameObject.GetComponent <FPSInputController> ()).enabled = true;
    15.                         ((MonoBehaviour)MyPlayerGO.gameObject.GetComponent <CharacterMotor> ()).enabled = true;
    16.                         ((MonoBehaviour)MyPlayerGO.gameObject.GetComponentInChildren <PlayerAnimate>()).enabled = true;
    17.                         ((MonoBehaviour)MyPlayerGO.gameObject.GetComponentInChildren <TextureFlip>()).enabled = true;
    18.                         //((MonoBehaviour)MyPlayerGO.gameObject.GetComponent <AnimateTexture>()).enabled = true;
    19.             randomPlayer.Remove(myPlayerWhite);
    20.  
    21.        
    22.                 } else if...
    My networked Character code:

    Code (csharp):
    1. ublic class NetworkCharacter : Photon.MonoBehaviour {
    2.  
    3.     private Vector3 realPosition ;
    4.  
    5.     // Use this for initialization
    6.     void Start () {
    7.    
    8.     }
    9.  
    10.     // Update is called once per frame
    11.     void Update () {
    12.  
    13.  
    14.         if (photonView.isMine) {
    15.             } else {
    16.             this.realPosition.z = 0;
    17.             transform.position = Vector3.Lerp(transform.position,this.realPosition,Time.deltaTime * 15);
    18.             }
    19.  
    20.     }
    21.  
    22.     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
    23.  
    24.         Debug.Log ("NetChar");
    25.         if (stream.isWriting) {
    26.             stream.SendNext(transform.position);
    27.  
    28.         } else {
    29.  
    30.             this.realPosition = (Vector3) stream.ReceiveNext();
    31.  
    32.  
    33.                 }
    34.     }
    35. }
    What do I need to have my Player2 Animate on my client.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    You have to look into what triggers your animations. They are most likely started by input but on the remote clients, the input targets some other character, right?
    You can either use the "Lerp to realPosition" code and detect how you are moving the remove character, or you can send some "state" value with the position to have an easier life.
    Have a look at the Photon Viking Demo in the Asset Store. There, we send position, rotation and I think a state for jumping, etc.
    The animations are not fully in sync but that's probably not a problem early on. Later you can think about lag compensation, etc...