Always receiving 0,0,0 with OnPhotonSerializeView
Options
juaxix
✭✭
Hi, following the Marco Polo tutorial ( http://doc.exitgames.com/en/pun/current ... marco-polo )
when I use this code
it always receive 0,0,0 as position and rotation, if i dont use the NetworkCharacter it works well, and I dont know how to fix it...
This is my code to test
am I doing something wrong?
when I use this code
using UnityEngine; public class NetworkCharacter : Photon.MonoBehaviour { private Vector3 correctPlayerPos; private Quaternion correctPlayerRot; // Update is called once per frame void Update() { if (!photonView.isMine) { transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5); transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5); } } void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { // We own this player: send the others our data stream.SendNext(transform.position); stream.SendNext(transform.rotation); } else { // Network player, receive data this.correctPlayerPos = (Vector3)stream.ReceiveNext(); this.correctPlayerRot = (Quaternion)stream.ReceiveNext(); } } }
it always receive 0,0,0 as position and rotation, if i dont use the NetworkCharacter it works well, and I dont know how to fix it...
This is my code to test
using UnityEngine; using System.Collections; public class NetworkCharacter : Photon.MonoBehaviour { private Vector3 correctPlayerPos; private Quaternion correctPlayerRot; // Update is called once per frame void Update() { /*if (!photonView.isMine && this.correctPlayerPos!=null && !System.Single.IsNaN(this.correctPlayerPos.x) && this.correctPlayerRot!=null && !System.Single.IsNaN(this.correctPlayerRot.x)) { if (Vector3.Distance(transform.position,this.correctPlayerPos)>2){ transform.position = this.correctPlayerPos; transform.rotation = this.correctPlayerRot; } else { transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 6); transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 6); } }*/ // Getting always 0,0,0: if (!photonView.isMine) Debug.Log(this.correctPlayerPos.ToString()); } void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { // We own this player: send the others our data stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(rigidbody.velocity); } else { // Network player, receive data this.correctPlayerPos = (Vector3)stream.ReceiveNext(); this.correctPlayerRot = (Quaternion)stream.ReceiveNext(); rigidbody.velocity = (Vector3)stream.ReceiveNext(); } } }
am I doing something wrong?
0
Comments
-
Hi,
Can you also log values during serialization to make sure that you send non-zero's?0 -
Did you drag and drop the component (on the Prefab) to the "Observed" field of PhotonView (on the same Prefab)?0