Player's Rotation isnot synch

So basically the player movement is working as it intended each player control his own controller.

The problem is coming from the rotation coz the rotation is not coming from the player component, its from gameobject that already in the scene.

The script is like that :

using System.Collections;

using System.Collections.Generic;

using Photon.Pun;

using UnityEngine;

public class ThirdPersonCam : MonoBehaviour

{

  [Header("References")]

  public Rigidbody rb;


  public float rotationSpeed;


  public GameObject thirdPersonCam;


  

  public void PlayerRotation()

  {

    // rotate orientation


    Vector3 viewDir = SpawnPointManager.Instance.PlayerMovement.gameObject.transform.position - new Vector3(transform.position.x, SpawnPointManager.Instance.PlayerMovement.gameObject.transform.position.y, transform.position.z);

    SpawnPointManager.Instance.PlayerMovement.orientation.forward = viewDir.normalized;


    // rotate player object

    float horizontalInput = Input.GetAxis("Horizontal");

    float verticalInput = Input.GetAxis("Vertical");

    Vector3 inputDir = SpawnPointManager.Instance.PlayerMovement.orientation.forward * verticalInput + SpawnPointManager.Instance.PlayerMovement.orientation.right * horizontalInput;


    if (inputDir != Vector3.zero)

      SpawnPointManager.Instance.PlayerMovement.playerObj.forward = Vector3.Slerp(SpawnPointManager.Instance.PlayerMovement.playerObj.forward, inputDir.normalized, Time.deltaTime * rotationSpeed);


  }


  private void Start()

  {


    Cursor.lockState = CursorLockMode.Locked;

    Cursor.visible = false;

  }


  private void Update()

  {

    if (SpawnPointManager.Instance.PlayerMovement.photonView.IsMine)

    {

      PlayerRotation();


    }

  }




}

I cant seem to make the rotation synch each player.

No matter what I was trying , adding Photonview to this + photonTransform.

tried to OnPhotonSerializeView and send the roation. - this made the master client move the client roation. but nothing else.

What am I missing?

Thanks

Answers

  • Can't really look into your code deeply. Just in general: You need to send the rotation and then you need some code to apply the received values in some way. Could be in Update() or somewhere else.

    It sounds as if you read some other object's rotation. Maybe you need to make sure that this object isn't setting some value to overwrite the values coming from remote?!

  • Thank for answering I fixed it by putting in those GO PhotonTransform.

    Idnk why stream didnt help but whatever. thanks!