How to sync chest LookAt() across network

Options
I have a player with a chest obtained in Start() and pointed towards a "target" cube I move up and down to simulate aiming. I am trying to send the direction of the chest over the network so the players can see the upward or downward direction the character is aiming. Is there a decently optimized way to send the "bending" of the spine over the network.

Public class PlayerMove : MonoBehaviourPun, IPunObservable{

public Transform chest;

void Start()
{
chest = animator.GetBoneTransform(HumanBodyBones.Chest);
}

void LateUpdate()
{
Camera.main.transform.LookAt(target.transform.position);
chest.LookAt(target.transform.position);
chest.rotation = chest.rotation * Quaternion.Euler(offset);
}
//Some camera movement stuff and unimportant, unrelated code below.
}


public class NetworkPlayer : MonoBehaviourPun, IPunObservable {

protected Vector3 realPosition = Vector3.zero;
protected Quaternion realRotation = Quaternion.identity;

private void Awake()
{
animator = GetComponentInChildren();
}

public void Update()
{
if (this.photonView.IsMine)
{
}
else
{
transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
}
}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(animator.GetFloat("Speed"));
stream.SendNext(animator.GetBool("IsGrounded"));
stream.SendNext(animator.GetFloat("JoyStickX"));
stream.SendNext(animator.GetFloat("JoyStickY"));
stream.SendNext(animator.GetFloat("AimAngle"));

}
else
{
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
animator.SetFloat("Speed",(float)stream.ReceiveNext());
animator.SetBool("IsGrounded",(bool)stream.ReceiveNext());
animator.SetFloat("JoyStickX",(float)stream.ReceiveNext());
animator.SetFloat("JoyStickY",(float)stream.ReceiveNext());
animator.SetFloat("AimAngle",(float)stream.ReceiveNext());
}
}
}


I've tried following all tutorials related to "Bone" & "sync" issues with Photon and even tried using RPC's but I cannot get the rotation of the upper body/chest to propagate over the network no matter what. Please if you can help I'd appreciate it!




Comments

  • Mrmug
    Options
    Solved. Apparently, nobody has actually solved this issue and anyone that's tried has reverted to Mechanim.


    public class NetworkPlayer : MonoBehaviourPun, IPunObservable
    {
    public Animator animator;
    public float aimAngle = 0;
    protected Vector3 realPosition = Vector3.zero;
    protected Quaternion realRotation = Quaternion.identity;
    public Quaternion chestRotation = Quaternion.identity;
    public Vector3 targetPosition = Vector3.zero;
    public Vector3 offset = new Vector3(10,56,12);
    public Transform local_head, local_neck, local_spine, local_chest = null;
    public Quaternion server_head, server_neck, server_spine, server_chest = Quaternion.identity;
    private int currentBoneRate = 0;
    public Quaternion local_chestQuaternion;
    public Transform target;
    Quaternion rot;



    public void LateUpdate()
    {
    if (this.photonView.IsMine)
    {
    //local_chest.rotation = Quaternion.Lerp(local_chest.rotation, chestRotation, 0.1f);
    //Do Nothing -- Everything is already enabled
    }
    else
    {
    local_chest.LookAt(target);
    target.position = Vector3.Lerp(target.position, targetPosition, 0.1f);
    local_chest.rotation = local_chest.rotation * Quaternion.Euler(offset);
    local_chest.rotation = Quaternion.Lerp(local_chest.rotation, chestRotation, 0.1f);
    }

    }

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    if (stream.IsWriting)
    {
    stream.SendNext(target.transform.position);
    stream.SendNext(local_chest.transform.rotation);
    stream.SendNext(transform.position);
    stream.SendNext(transform.rotation);
    stream.SendNext(animator.GetFloat("Speed"));
    stream.SendNext(animator.GetBool("IsGrounded"));
    stream.SendNext(animator.GetFloat("JoyStickX"));
    stream.SendNext(animator.GetFloat("JoyStickY"));
    stream.SendNext(animator.GetFloat("AimAngle"));

    }
    else
    {
    //This is someone else' player. we need to get their positions
    //as of a few milliseconds ago and update or version of that player
    targetPosition = (Vector3)stream.ReceiveNext();
    chestRotation = (Quaternion)stream.ReceiveNext();
    realPosition = (Vector3)stream.ReceiveNext();
    realRotation = (Quaternion)stream.ReceiveNext();
    animator.SetFloat("Speed",(float)stream.ReceiveNext());
    animator.SetBool("IsGrounded",(bool)stream.ReceiveNext());
    animator.SetFloat("JoyStickX",(float)stream.ReceiveNext());
    animator.SetFloat("JoyStickY",(float)stream.ReceiveNext());
    animator.SetFloat("AimAngle",(float)stream.ReceiveNext());
    }
    }
    }