Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Third Party Player Rotation not syncing Please Help [Mirror]

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

  1. Fishgethirsty

    Fishgethirsty

    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. Fishgethirsty

    Fishgethirsty

    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.