I have an issue with synchronizing my characters rotation.
The character has these things attatched:
CapsuleCollider, Rigidbody,
PhotonView, PhotonRigisbodyView, PhotonTransformView, PhotonAnimatorView,
NetworkPlayerPhoton
When entering a Map, the character (the MeshPlayer) is being spawned and made as a Child of an EmptyGameObject called "Player".
The "Player" GameObject has the PhotonView and PhotonTransformView attatched.
When I build the Game and run it on 2 Android devices, and move a character, on the other Device the position of the character is being updated but not the rotation of it and also not the ("Run" Animation).
This is the NetworkPlayerPhoton Script which is there for synchronizing everything:
public class NetworkPlayerPhoton : MonoBehaviourPun, IPunObservable
{
private Transform character;
private Transform personalCamera;
private FGroundFitter_Demo_JoystickInput joystickInput;
private SingleAttack singleAttack;
private AnimalTigerRoar animalRoar;
private Rigidbody r;
//For smoothing the Movement of other Characters
Vector3 latestPos;
Quaternion latestRot;
Vector3 velocity;
Vector3 angularVelocity;
bool valuesReceived = false;
//Link the Animator
private Animator animator;
private void Start()
{
if (photonView.IsMine)
{
GetComponent<FGroundFitter_Demo_JoystickInput>().enabled = true;
GetComponent<SingleAttack>().enabled = true;
GetComponent<AnimalTigerRoar>().enabled = true;
personalCamera.gameObject.SetActive(true);
}
else
{
Destroy(character);
Destroy(this);
}
}
private void FixedUpdate()
{
GetNeededComponents();
}
private void GetNeededComponents()
{
GameObject temporaryCamera = GameObject.FindGameObjectWithTag("Camera");
personalCamera = temporaryCamera.transform.GetChild(0);
GameObject temporaryPlayer = GameObject.FindGameObjectWithTag("Player");
character = temporaryPlayer.transform.GetChild(0);
joystickInput = GetComponent<FGroundFitter_Demo_JoystickInput>();
singleAttack = GetComponent<SingleAttack>();
animalRoar = GetComponent<AnimalTigerRoar>();
animator = GetComponent<Animator>();
r = GetComponent<Rigidbody>();
}
//Send the Character Position and Rotation through the Server
public 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(r.velocity);
stream.SendNext(r.angularVelocity);
stream.SendNext(animator.GetBool("Walk"));
stream.SendNext(animator.GetBool("Run"));
stream.SendNext(animator.GetBool("Sound"));
stream.SendNext(animator.GetBool("Attack"));
}
else
{
// Network player, receive data
latestPos = (Vector3)stream.ReceiveNext();
latestRot = (Quaternion)stream.ReceiveNext();
velocity = (Vector3)stream.ReceiveNext();
angularVelocity = (Vector3)stream.ReceiveNext();
animator.SetBool("Walk", (bool)stream.ReceiveNext());
animator.SetBool("Run", (bool)stream.ReceiveNext());
animator.SetBool("Sound", (bool)stream.ReceiveNext());
animator.SetBool("Attack", (bool)stream.ReceiveNext());
valuesReceived = true;
}
}
private void Update()
{
if (!photonView.IsMine && valuesReceived)
{
//Update Object position and Rigidbody parameters
transform.position = Vector3.Lerp(transform.position, latestPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, latestRot, Time.deltaTime * 5);
r.velocity = velocity;
r.angularVelocity = angularVelocity;
}
}
void OnCollisionEnter(Collision contact)
{
if (!photonView.IsMine)
{
Transform collisionObjectRoot = contact.transform.root;
if (collisionObjectRoot.CompareTag("MeshPlayer"))
{
//Transfer PhotonView of Rigidbody to our local player
photonView.TransferOwnership(PhotonNetwork.LocalPlayer);
}
}
}
}