Child rotation will not update

I have set up Photon multiplayer and the characters transform, rotation, and animations are synced. The weapon however which is attached to the right hand will not sync its rotation. I think I have tried just about everything at this point. I have attached its own photonview and transformview, I have tried to do it through scripts. I'm about to quit and go to the unity built in...

this is the transformview :
namespace Photon.Pun
{
    using UnityEngine;
    using UnityStandardAssets.Characters.FirstPerson;

    public class PlayerTransform : MonoBehaviour, IPunObservable
    {

        public GameObject Weapon;
        private Quaternion looking;
        private Quaternion clavicleLooking;

        private float m_Distance;
        private float m_Angle;
        private float m_WeaponAngle;

        private PhotonView m_PhotonView;

        private Vector3 m_Direction;
        private Vector3 m_NetworkPosition;
        private Vector3 m_StoredPosition;
        public Vector3 m_NetworkLHandPosition;

        private Quaternion m_NetworkRotation;
        public Quaternion m_NetworkWeaponRotation;
        public Quaternion m_NetworkLClavicleRotation;
        public Quaternion m_NetworkHandRotation;

        public bool m_SynchronizePosition = true;
        public bool m_SynchronizeRotation = true;
        public bool m_SynchronizeWeapon = true;
        public bool m_SynchronizeScale = false;
        public USWeaponSwitching usweaponswitching;
        public USFirstPersonController usfpsControl;

        public void Awake()
        {
            m_PhotonView = GetComponent<PhotonView>();

            m_StoredPosition = transform.position;
            m_NetworkPosition = Vector3.zero;

            m_NetworkRotation = Quaternion.identity;

        }

        public void Update()
        {
            if (!this.m_PhotonView.IsMine)
            {
                transform.position = Vector3.MoveTowards(transform.position, this.m_NetworkPosition, this.m_Distance * (1.0f / PhotonNetwork.SerializationRate));
                transform.rotation = Quaternion.RotateTowards(transform.rotation, this.m_NetworkRotation, this.m_Angle * (1.0f / PhotonNetwork.SerializationRate));
                // Weapon.transform.rotation = Quaternion.RotateTowards(Weapon.transform.rotation, this.m_NetworkWeaponRotation, this.m_WeaponAngle * (1.0f / PhotonNetwork.SerializationRate));
                usweaponswitching.hand.transform.rotation = Quaternion.RotateTowards(usweaponswitching.hand.transform.rotation, this.m_NetworkHandRotation, m_WeaponAngle);
                usweaponswitching.lhand.transform.position = Vector3.MoveTowards(usweaponswitching.lhand.transform.position, this.m_NetworkLHandPosition, m_WeaponAngle);
                usweaponswitching.lClavicle.transform.rotation = Quaternion.RotateTowards(usweaponswitching.lClavicle.transform.rotation, this.m_NetworkLClavicleRotation, m_WeaponAngle);

            }
            else
            {
                //clavicleLooking = usweaponswitching.lClavicle.transform.rotation;
                //clavicleLooking *= Quaternion.Euler(0f, -usweaponswitching.cam.transform.eulerAngles.x, 0f);
                //looking = usweaponswitching.hand.transform.rotation;
                //looking *= Quaternion.Euler(0f, -usweaponswitching.cam.transform.eulerAngles.x, 0f);
                //usweaponswitching.hand.transform.rotation = looking;
                //if (usfpsControl.handLocked)
                //{
                //    usweaponswitching.lhand.transform.position = usweaponswitching.handHold.transform.position;
                //    usweaponswitching.lClavicle.transform.rotation = clavicleLooking;
                //}
                
            }

        }

        public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            if (stream.IsWriting)
            {
                if (this.m_SynchronizePosition)
                {
                    this.m_Direction = transform.position - this.m_StoredPosition;
                    this.m_StoredPosition = transform.position;

                    stream.SendNext(transform.position);
                    stream.SendNext(this.m_Direction);
                }

                if (this.m_SynchronizeRotation)
                {
                    stream.SendNext(transform.rotation);

                }

                if (this.m_SynchronizeWeapon)
                {
                    stream.SendNext(Weapon.transform.rotation);
                    stream.SendNext(usweaponswitching.hand.transform.rotation);
                    stream.SendNext(usweaponswitching.lhand.transform.position);
                    stream.SendNext(usweaponswitching.lClavicle.transform.rotation);
                }

                if (this.m_SynchronizeScale)
                {
                    stream.SendNext(transform.localScale);
                }
            }
            else
            {
                if (this.m_SynchronizePosition)
                {
                    this.m_NetworkPosition = (Vector3)stream.ReceiveNext();
                    this.m_Direction = (Vector3)stream.ReceiveNext();

                    float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.timestamp));
                    this.m_NetworkPosition += this.m_Direction * lag;

                    this.m_Distance = Vector3.Distance(transform.position, this.m_NetworkPosition);
                }

                if (this.m_SynchronizeRotation)
                {
                    this.m_NetworkRotation = (Quaternion)stream.ReceiveNext();

                    this.m_Angle = Quaternion.Angle(transform.rotation, this.m_NetworkRotation);

                }

                if (this.m_SynchronizeWeapon)
                {
                    this.m_NetworkWeaponRotation = (Quaternion)stream.ReceiveNext();
                    this.m_WeaponAngle = Quaternion.Angle(Weapon.transform.rotation, this.m_NetworkWeaponRotation);
                    this.m_NetworkHandRotation = (Quaternion)stream.ReceiveNext();
                    
                    this.m_NetworkLHandPosition = (Vector3)stream.ReceiveNext();
                    this.m_NetworkLClavicleRotation = (Quaternion)stream.ReceiveNext();
                }

                if (this.m_SynchronizeScale)
                {
                    transform.localScale = (Vector3)stream.ReceiveNext();
                }
            }
        }
    }
}
this is where I update the weapon rotation:

private void LateUpdate() { //weapon movement if (PV.IsMine) { clavicleLooking = lClavicle.transform.rotation; clavicleLooking *= Quaternion.Euler(0f, -cam.transform.eulerAngles.x, 0f); looking = hand.transform.rotation; looking *= Quaternion.Euler(0f, -cam.transform.eulerAngles.x, 0f); hand.transform.rotation = looking; if (USfpsControl.handLocked) { lhand.transform.position = handHold.transform.position; lClavicle.transform.rotation = clavicleLooking; } }

Any help is appreciated!

Comments

  • Hi @Levi,

    in another thread you have said, that you receive updates on the remote client, however you mentioned, that those values don't change even when the weapon is moving. Have you checked which values you send? Are those updated properly?

    Have you already tried using the local values of the weapon, such as transform.localPosition or transform.localRotation?
  • Levi
    Levi
    edited November 2018

    Hi @Levi,

    in another thread you have said, that you receive updates on the remote client, however you mentioned, that those values don't change even when the weapon is moving. Have you checked which values you send? Are those updated properly?

    Have you already tried using the local values of the weapon, such as transform.localPosition or transform.localRotation?

    Thank you for the response. I have tried that and I checked that this is the rotation that is changing in the inspector while running the game. I am resulting to redesigning the character so the weapons can be a child of the camera and will align the position on the character through script. Hopefully that will resolve this. I will update this if it works.

    UPDATE : This did not resolve it. I think I am officially out of ideas.