- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
programmrzinc · Jul 24, 2015 at 07:08 PM ·
networkingphoton
Syncing Info from Networked Remote Player to Local
I have a plane game, where position info and other metrics are synced from the local player to their remote player on other clients, but how to I sync info from the remote player back to the sam local player, such as health? Here's a snippit of what I have, but its not syncing as is should
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
//Debug.Log("View is Serialized");
if (stream.isWriting)
{
//Our player
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(Input.GetAxis("Fire") ==-1f);
stream.SendNext(weapon.CurrentWeapon);
stream.SendNext(damage.HP);
}
else
{
//someone else's player
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
realFiring = (bool)stream.ReceiveNext();
realWeapon = (int)stream.ReceiveNext();
realDamage = (int)stream.ReceiveNext();
}
}
void Update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(this.transform.position, realPosition, Time.deltaTime * 15);
transform.rotation = Quaternion.Lerp(this.transform.rotation, realRotation, Time.deltaTime * 30);
weapon.CurrentWeapon = realWeapon;
if (realFiring)
{
weapon.LaunchWeapon();
}
}
else
{
damage.HP = realDamage;
print(realDamage);
}
}
Comment
Each player just sends it's own updates to the others. The inco$$anonymous$$g data is for remote planes and which are not controlled locally, so you have to move remote planes to the reported positions in Update() (e.g.) or fixed update.
Your answer