Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Third Party Photon Cloud Sending and Receiving transform information

Discussion in 'Multiplayer' started by xixgames, Aug 4, 2014.

  1. xixgames

    xixgames

    Joined:
    Jan 20, 2014
    Posts:
    31
    I wrote this entry in the photon cloud forums but nobody answered, so here is the problem, i have a cars game I did following the Marco Polo tutorial, create the scene, added PC libs, configure app for EU cloud server, create the cars entities with photon views, create the match making. Fine, it works, I can see the cars moving online from different platforms, but they have a movement kinda jerky , teleportating. Well, then I add the networkCharacter class:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NetworkCharacter : Photon.MonoBehaviour
    5. {
    6.    private Vector3 correctPlayerPos;
    7.    private Quaternion correctPlayerRot;
    8.  
    9.  
    10.    // Update is called once per frame
    11.    void Update()
    12.    {
    13.       /*if (!photonView.isMine && this.correctPlayerPos!=null && !System.Single.IsNaN(this.correctPlayerPos.x) && this.correctPlayerRot!=null && !System.Single.IsNaN(this.correctPlayerRot.x))
    14.       {
    15.          if (Vector3.Distance(transform.position,this.correctPlayerPos)>2){
    16.             transform.position = this.correctPlayerPos;
    17.             transform.rotation = this.correctPlayerRot;
    18.          } else {
    19.             transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 6);
    20.             transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 6);
    21.          }
    22.       }*/
    23.         // Getting always 0,0,0:
    24.           if (!photonView.isMine)
    25.       Debug.Log(this.correctPlayerPos.ToString());
    26.    }
    27.  
    28.    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    29.    {
    30.       if (stream.isWriting)
    31.       {
    32.          // We own this player: send the others our data
    33.          stream.SendNext(transform.position);
    34.          stream.SendNext(transform.rotation);
    35.          stream.SendNext(rigidbody.velocity);
    36.       }
    37.       else
    38.       {
    39.          // Network player, receive data
    40.          this.correctPlayerPos = (Vector3)stream.ReceiveNext();
    41.          this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
    42.          rigidbody.velocity = (Vector3)stream.ReceiveNext();
    43.       }
    44.  
    45.    }
    46. }
    in the car prefabs, but they send positions 0,0,0 but it is not true, they are not in 0,0,0 so...anyone knows what's going on?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    It was Sunday here and Exit Games was enjoying a hot summer weekend in Hamburg.
    I answered in your post. Let me know if that is it.
     
  3. xixgames

    xixgames

    Joined:
    Jan 20, 2014
    Posts:
    31
    OK, thanks, I'm answering there :)
     
  4. xixgames

    xixgames

    Joined:
    Jan 20, 2014
    Posts:
    31
    I just needed to drag the NetworkCharacter.cs component from the name in the prefab to the observer field in PhotonView component inside the same prefab. Thanks tobiass!
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    Glad you found it! Thanks for letting me know, too.