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 Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Players Position not Syncing despite Transform view component Photon

Discussion in 'Multiplayer' started by VeryNewAtThis, Jun 21, 2021.

  1. VeryNewAtThis

    VeryNewAtThis

    Joined:
    Jun 21, 2020
    Posts:
    5
    Hi all, I am currently making a multiplayer fps game and am running into a few issues. While Player rotation seems to be syncing between players, positions aren't and the player sees the other player as stuck at (0,0,0) despite the position being ticked on the Player's Photon Transform View Component.

    I am loosely following on from this tutorial
    .

    Thankyou in advance for any suggestions.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Photon.Pun;
    4. using UnityEngine;
    5. using UnityEngine.Audio;
    6.  
    7. public class PlayerController : MonoBehaviour
    8. {
    9.     public float walkSpeed = 20f;
    10.     private float sprintFactor;
    11.     public float jumpFactor = 5f;
    12.     public float gravity = 9.8f;
    13.     public Camera Cam;
    14.     public float CamSensitivity = 2.5f;
    15.     public float XClamp = 45.0f;
    16.     private float XMovement;
    17.     private float YMovement;
    18.  
    19.     CharacterController cc;
    20.     private PhotonView pv;
    21.     private Animator animator;
    22.     Vector3 direction = Vector3.zero;
    23.     float rotationX = 0;
    24.  
    25.     [HideInInspector]
    26.     public bool Move = true;
    27.  
    28.     public static bool running;
    29.  
    30.     void Start()
    31.     {
    32.         cc = GetComponent<CharacterController>();
    33.         animator = GetComponent<Animator>();
    34.         pv = GetComponent<PhotonView>();
    35.         CursorLock();
    36.  
    37.         if (!pv.IsMine)
    38.         {
    39.             Destroy(GetComponentInChildren<Camera>().gameObject);
    40.         }
    41.     }
    42.  
    43.     void Update()
    44.     {
    45.         if (!pv.IsMine) return;
    46.         running = Input.GetKey(KeyCode.LeftShift);
    47.         sprintFactor = running ? 1.5f : 1f;
    48.         XMovement = Move ? Input.GetAxis("Vertical") * sprintFactor * walkSpeed : 0f;
    49.         YMovement = Move ? Input.GetAxis("Horizontal") * sprintFactor * walkSpeed : 0f;
    50.         float Ydirection = direction.y;
    51.         direction = (transform.forward * XMovement) + (transform.right * YMovement);
    52.         if (Input.GetButton("Jump") && Move && cc.isGrounded)
    53.         {
    54.             direction.y = jumpFactor;
    55.             animator.SetBool("isJumping", true);
    56.         }
    57.         else
    58.         {
    59.             direction.y = Ydirection;
    60.             animator.SetBool("isJumping", false);
    61.         }
    62.         if (!cc.isGrounded)
    63.         {
    64.             direction.y -= gravity * Time.deltaTime;
    65.         }
    66.         cc.Move(direction * Time.deltaTime);
    67.         if (Move)
    68.         {
    69.             rotationX += -Input.GetAxis("Mouse Y") * CamSensitivity;
    70.             rotationX = Mathf.Clamp(rotationX, -XClamp, XClamp);
    71.             Cam.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
    72.             transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * CamSensitivity, 0);
    73.         }
    74.     }
    75.     private void CursorLock()
    76.     {
    77.         Cursor.lockState = CursorLockMode.Locked;
    78.         Cursor.visible = false;
    79.     }
    80. }
    upload_2021-6-21_12-2-6.png
     
    Last edited: Jun 21, 2021
  2. unity_TMhR7IoONty-HA

    unity_TMhR7IoONty-HA

    Joined:
    Dec 26, 2020
    Posts:
    4
    me to man can you fix this?
     
  3. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    195
    Try unticking "Use Local". Also ideally this is on a root gameobject?