Hello everyone!
So, this is my first time trying to write a game with photon pun but I’ve been facing some problems with synchronization.
Let’s say there are 2 players - A and B.
When A moves 3 m in 45 degrees, on the B’s view, A only move 45 degrees. It remains in its original position.
Similarly, if B moves 3 m in 45 degrees, on A’s view, B only move 45 degrees at its original position.
So, it seems to me that the photon transform view is not syncing the position of the character.
Here is my code for player movement in case it might help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
[RequireComponent(typeof(CharacterController), typeof(Animator))]
public class player_contoller : MonoBehaviourPun
{
private CharacterController characterController;
private Animator animator;
public Joystick joystick;
public Jumpbutton jumpbutton;
[SerializeField]
private float movementSpeed, rotationSpeed, jumpSpeed, gravity;
private Vector3 movementDirection = Vector3.zero;
private bool playerGrounded;
// Start is called before the first frame update
void Start()
{
characterController = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
jumpbutton = FindObjectOfType<Jumpbutton>();
joystick = FindObjectOfType<Joystick>();
}
// Update is called once per frame
void Update()
{
if (photonView.IsMine)
{
TakeInput();
}
}
private void TakeInput()
{
playerGrounded = characterController.isGrounded;
//movement
Vector3 inputMovement = transform.forward * movementSpeed * joystick.Vertical;
characterController.Move(inputMovement * Time.deltaTime);
transform.Rotate(Vector3.up * joystick.Horizontal * rotationSpeed);
//jumping
if (jumpbutton.Pressed && playerGrounded)
{
movementDirection.y = jumpSpeed;
}
movementDirection.y -= gravity * Time.deltaTime;
characterController.Move(movementDirection * Time.deltaTime);
//animations
animator.SetBool("isRunning", joystick.Vertical != 0);
animator.SetBool("isJumping", !characterController.isGrounded);
}
}
Here is my player prefab but I think I have attached all the components correctly.
Any helps or suggestions would be much appreciated ![]()