Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Unity Multiplayer Player Rotation not syncing Please Help [Mirror]

Discussion in 'Multiplayer' started by dofishgethirsty, Aug 4, 2022.

  1. dofishgethirsty

    dofishgethirsty

    Joined:
    Dec 11, 2020
    Posts:
    4
    Hello, I'm making a 2D game and the rotation works by the player rotates towards the mouse and it works great with one player but when there is more then one player the client rotates fine but you don't see the rotation of all the other players. Thank you!!

    Code (CSharp):
    1. public class PlayerRotation : NetworkBehaviour
    2. {
    3.     public GameObject PlayerSprite;
    4.  
    5.     private void Update()
    6.     {
    7.         if (!isLocalPlayer) { return; }
    8.  
    9.         rotateToMouse();
    10.     }
    11.  
    12.     private void rotateToMouse()
    13.     {
    14.         Vector3 mousePosition = Input.mousePosition;
    15.         mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
    16.         mousePosition.z = 0f;
    17.         Vector2 direction = new Vector2(
    18.         mousePosition.x - transform.position.x,
    19.         mousePosition.y - transform.position.y);
    20.  
    21.         PlayerSprite.transform.up = direction;
    22.     }
    23. }
     
  2. etiennef

    etiennef

    Joined:
    Apr 1, 2015
    Posts:
    6
    Hello dofishgethirsty,

    Are you sure that you have a Network Transform component on your Player object, so it can sync with others ?

    Cheers
     
  3. dofishgethirsty

    dofishgethirsty

    Joined:
    Dec 11, 2020
    Posts:
    4
    Hello etiennef and thanks for responding!

    Yes, I made sure I have the network transform with sync rotation ticked and I have the network identity.