Question about tracking player movement, and camera rotation

Options
For what we're doing, I need to have the photonview serialize the player position, and the camera rotation. I think this was leading to a "bug" that we were having trouble with. Right now it only tracks and sends the player's rotation and movement, not the camera's vertical look.

Is there an easy way to add that in? Or do I need to add a photon view to the camera, and a script to serialize it the same way we did the player?

For the network character the code we have is basically the same as the marco polo tutorial:

[code2=csharp]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)
{
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();
}
}

}[/code2]

EDIT: For now I just added another photonview and script to the camera, seems to work fine. If there is a better solution though please let me know :)

Comments

  • Tobias
    Options
    Glad you found a fix.
    You don't exactly have to use another PV but I guess it's the easiest way.
    You could also include the cam's pos in your own OnPhotonSerializeView() implementation. If only one player should control the cam, you could include the extra data if that player is master or not. On the receiving end, you'd check how long the incoming stream is or check it's content.

    That said: Another PV is just fine :)
  • I will have to play around with that. Thank you :) And that way we have a backup with the extra PV