[SOLVED]Photon Smoothing Player Movement
Options
xXGriMe
✭
So im stuck right now and cant figure out whats going on here. I have a script called PhotonViewer that is basically responsible for enabling player components and writing and receiving player positions. Everything works great i can have more than 1 player join and both clients are able to observe each other just fine. However when a player moves is very choppy/laggy for the other player observing the movement. So i added code to smooth the player but it seems to have no effect at all. Can someone take a look at the code and see if you can help me out here. I was loosely following the merry fragmass tut found here http://unity3d.com/learn/tutorials/...i ... ayer-fps-2
PhontonViewer.cs
PhontonViewer.cs
using UnityEngine; using System.Collections; public class PhotonViewer : Photon.MonoBehaviour { Vector3 position; Quaternion rotation; float smoothing = 10f; // Use this for initialization void Start () { PhotonView pv = PhotonView.Get(this); if (pv.isMine) { GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<AudioListener>().enabled = true; GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<Camera>().enabled = true; GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<MyMouseLook>().enabled = true; GameObject.FindGameObjectWithTag ("Player").GetComponent<CharacterController>().enabled = true; GameObject.FindGameObjectWithTag ("Player").GetComponent<CharacterMotor>().enabled = true; GameObject.FindGameObjectWithTag ("Player").GetComponent<FPSInputController>().enabled = true; print (PhotonNetwork.player.ID); } else { StartCoroutine("UpdateData"); } } IEnumerator UpdateData() { while(true) { transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * smoothing); transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * smoothing); yield return null; } } public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting) { //print ("writing"); stream.SendNext(transform.position); stream.SendNext(transform.rotation); } else { //print ("reciving"); position = (Vector3)stream.ReceiveNext(); rotation = (Quaternion)stream.ReceiveNext(); } } // Update is called once per frame void Update () { } }
0
Comments
-
The issue was fixed by removing the player transform from being observed.0