UNET Network Transform Child not synchronizing

Hi guys,

following issue:

I have a pretty basic unet multiplayer game, with multiple players running around… all working so far. but now i want each player’s legs to face the direction which he’s walking. i’m doing this by using transform.localEulerAngles and it works well in for each player (no matter if host or client), but one player doesn’t see other player’s legs rotating, so there is no synchronization.

the legs are a child object of the player, who has a network identity and network transform and a network transform child component attached (with the legs attached as the child target).

The player has a PlayerMovement script, where the walkingRight, walkingLeft, walkingForward etc. variables of the LegsRotation script are adjusted to the current movement. the LegsRotation script should then handle the rest of it:

PlayerMovement script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class PlayerMovement : NetworkBehaviour
{
    //Movement Variables
    public float speed;       
    public float sensitivity = 3f;
    private float yaw = 0f;

    public GameObject legs;
    public Animator anim;
    public Transform tf;

    Rigidbody rb;
   
    private void Start()
    {
        tf = GetComponent<Transform>();
        rb = GetComponent<Rigidbody>();
        anim = GetComponent<Animator>();                       
    }

    private void Update()
    {
       [COLOR=#000000] //Only for local player...
        if (!isLocalPlayer)
        {
            return;
        }

        //Movement    
        legs.GetComponent<LegsRotation>().walkingRight = false;
        legs.GetComponent<LegsRotation>().walkingLeft = false;
        legs.GetComponent<LegsRotation>().walkingForwards = false;
        legs.GetComponent<LegsRotation>().walkingBackwards = false;
        if (Input.GetKey(KeyCode.W))
        {
            walk(0, 0, 1);
            legs.GetComponent<LegsRotation>().walkingForwards = true;
        }
        if (Input.GetKey(KeyCode.S))
        {
            walk(0, 0, -1);
            legs.GetComponent<LegsRotation>().walkingBackwards = true;
        }
        if (Input.GetKey(KeyCode.D))
        {
            walk(1, 0, 0);
            legs.GetComponent<LegsRotation>().walkingRight = true;
        }
        if (Input.GetKey(KeyCode.A))
        {
            walk(-1, 0, 0);
            legs.GetComponent<LegsRotation>().walkingLeft = true;
        }[/COLOR]

        //Mouse View                                                   
        yaw += sensitivity * Input.GetAxis("Mouse X");
        transform.eulerAngles = new Vector3(0f, yaw, 0f);
    }

    void walk(int x, int y, int z)
    {
        tf.Translate(x*speed, y*speed, z*speed);
    }
}

LegsRotation script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LegsRotation : MonoBehaviour
{
    public bool walkingRight = false;
    public bool walkingLeft = false;
    public bool walkingForwards = false;
    public bool walkingBackwards = false;

    private void Update()
    {
        transform.localEulerAngles = new Vector3(270f, 0f, 0f);

        if (walkingForwards && !walkingBackwards)
        {
            transform.localEulerAngles = new Vector3(270f, 0f, 0f);
            if (walkingRight && !walkingLeft) transform.localEulerAngles = new Vector3(270f, 45f, 0f);
            if (walkingLeft && !walkingRight) transform.localEulerAngles = new Vector3(270f, 315f, 0f);
        }
        if (walkingBackwards && !walkingForwards)
        {
            transform.localEulerAngles = new Vector3(270f, 180f, 0f);
            if (walkingRight && !walkingLeft) transform.localEulerAngles = new Vector3(270f, 135f, 0f);
            if (walkingLeft && !walkingRight) transform.localEulerAngles = new Vector3(270f, 225f, 0f);
        }
        if (walkingRight && !walkingForwards && !walkingBackwards && !walkingLeft)
        {
            transform.localEulerAngles = new Vector3(270f, 90f, 0f);
        }
        if (walkingLeft && !walkingForwards && !walkingBackwards && !walkingRight)
        {
            transform.localEulerAngles = new Vector3(270f, 270f, 0f);
        }
    }
}

do you have any idea, why it isn’t working? i thought that every transformation/rotation gets synchronized, when you do network transform, no matter how the transformation is initiated… do i have to run the code for this on the server?

Thanks for your ideas and also for studying my case :smile:

Ok problem solved …

It would be nice if you tell us how you solved it!

1 Like

Omg what was the solution. I have the same problem :frowning:

It seems joestyler sadly make a mystery about it…

Would you like to share your answer? Other people could benefit from knowing your answer

Okay, I had a very similar issue. My players would move around in the world, but their heads would not rotate for each other except locally.

Not sure if my issue is the same as you, but I was accidentally only grabbing the transform of my player’s head model, but technically it was the head’s parent gameobject that was moving the model, so both the gameobject with the mesh renderer for the 3d model as well as the parent gameobject which rotated the model, needed to be dragged into a NetworkTransformChild component on the root gameobject.

In my case it was just a silly mistake, but had the same result, so I figured I’d at least throw it as a possible answer.

For anyone still looking for this and using mirror i found that enabling Client Authority makes it work.7271380--878131--upload_2021-6-25_15-10-27.png

1 Like