Child rotation wont sync
Hello all! I am trying to sync a weapons rotation which is a child component. I rotate the weapon using this:
which works but, the other player just sees the weapon staying in one location. The parent transform, and rotation works using this:
As you can see I have tried specifically sending the components rotation but, there is no change. I have tried adding its own photon view and transform view as well. Nothing seems to work. Thank you for the help!
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;
}
}
which works but, the other player just sees the weapon staying in one location. The parent transform, and rotation works using this:
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();
}
}
}
}
}
As you can see I have tried specifically sending the components rotation but, there is no change. I have tried adding its own photon view and transform view as well. Nothing seems to work. Thank you for the help!
0
Comments
-
Additional information : I am receiving values for all of the sent streams however they do not change when the weapon moves.0
This discussion has been closed.