Network Rotation not sync

My Unity version is 5.2.3f1, I m trying to sync the rotation of a child gameobject, in local works perfectly fine but it doesnt show up in other clients. I tried everything I could find and nothing.

The reason of this is to rotate a FPS body, so, I m trying to rotate Spine2 (Rotate the camera is not my best solution). I m using a Mixamo character to test, in the end I will have Mixamo auto-rigged charscters so everything I make here will be compatible.

I tried to use the Network Transform Rigidbody 3D and it only sync the character itself, not Spine2, I have tried Network Transform Child, and this: skeleton-sync.

In the script part, I have tried a lot of things, the most promising one was this:

[SyncVar]
private Quaternion syncPlayerRotation;

[SerializeField]
private Transform playerTransform;
[SerializeField]
private float lerpRate = 15f;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void LateUpdate () {
    TransmitRotations();
    LerpRotations();
}

void LerpRotations()
{
    if (!isLocalPlayer)
    playerTransform.localRotation = Quaternion.Lerp(playerTransform.localRotation, syncPlayerRotation, Time.deltaTime * lerpRate);
}

[Command]
void CmdProvideRotationsToServer(Quaternion playerRot)
{
    syncPlayerRotation = playerRot;
}

[Client]
void TransmitRotations()
{
    if (isLocalPlayer)
    {
        CmdProvideRotationsToServer(playerTransform.localRotation);
    }
}

Its from here

I attached it to Spine2 and still dont work, but when I attached it to the main character, it worked.

Also tried this:

void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
    Vector3 syncPosition = Vector3.zero;
    if (stream.isWriting)
    {
        syncPosition = Spine.GetComponent<Rigidbody>().position;
        stream.Serialize(ref syncPosition);
    }
    else
    {
        stream.Serialize(ref syncPosition);
        Spine.GetComponent<Rigidbody>().position = syncPosition;
    }
}

But I think it was for an older version of Unity.

To make the rotations I m using A Free Simple Smooth Mouselook

I edited it, this lines:

if (Input.GetMouseButton(1))
        {
            var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.forward);
            transform.localRotation = xRotation;

        }
        else
        {
            var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right);
            transform.localRotation = xRotation;
        }

Basicly, I changed Vector3.right to Vector3.forward and converted the Vector3.right only if the right mouse button is not pressed. The script is attached to Spine2 and its activated on the start if(isLocalPlayer) by script.

There’s a pic of the current hierarchy:
[4]
(some cameras are there only to test, the main camera is FirstPersonCamera, extracted from the standard assets)

I noticed that if I debug log the Spine2 rotation, it only gives me values from 0 to 1.

Absolutely any response will be helpful, thanks!

You probably want to use the components NetworkTransform and NetworkTransformChild appropriately on your objects.

I had troubles getting rotations to sync across the network, on child objects on my player (like the gun), until I discovered that I needed to put an extra NetworkTransformChild on the root player object, and drop the Weapon object onto that. Add another NetworkTransformChild to any children game objects that you need to sync position and rotation across the server!

All the best!

  • Murray

Any news on this? I have a similar problem:

in the Update() method I move/rotate my player. I have NetworkTransformChild on his head (bone) to let the players head look around and everything works great and syncs over the network. (Mirror Networking Library)

BUT:

When I animate the player and character is walking I cannot deform bones because this deform will be resetted by the animator. So I found out that I can use LateUpdate() to deform the head bone. So in Update() the character is animated and in LateUpdate() the head is transformed. This works locally but is not synced over the network because Unity networking / mirror networking dont seem to sync this. Whats the right way to do this?