Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

PUN Syncing is terrible ...

$
0
0
I'm gonna put this short. My syncing is terrible - the other players are gliding around, and stops moving about three seconds after actually stopping. I'm a tad bit new to networking, but here is my player code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : Photon.MonoBehaviour { private Animator anim; private CharacterController controller; public float speed = 6.0f; public float turnSpeed = 60.0f; private Vector3 moveDirection = Vector3.zero; public float gravity = 20.0f; private Vector3 selfPos; public PhotonView photonView; public GameObject plCam; // Use this for initialization void Start () { anim = gameObject.GetComponentInChildren(); controller = GetComponent(); } private void Awake () { if(photonView.isMine) { plCam.SetActive(true); } else { plCam.SetActive(false); } } private void Update () { if(photonView.isMine) checkInput(); else smoothNetMovement(); } private void checkInput () { if(Input.GetKey(KeyCode.W)) { anim.SetFloat("AnimPar", 1); } else { anim.SetFloat("AnimPar", 0); } if(controller.isGrounded) { moveDirection = transform.forward * Input.GetAxis("Vertical") * speed; } float turn = Input.GetAxis("Horizontal"); transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0); controller.Move(moveDirection * Time.deltaTime); moveDirection.y -= gravity * Time.deltaTime; } private void smoothNetMovement () { transform.position = Vector3.Lerp(transform.position, selfPos, Time.deltaTime); } private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting) { stream.SendNext(transform.position); stream.SendNext(transform.rotation); } else { selfPos = (Vector3)stream.ReceiveNext(); } } }

Viewing all articles
Browse latest Browse all 8947

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>