The Position with Smooth From Marco Polo not corrcet! Help

GUYS I have problem that i have work on it for maybe almost week and can't find solution :cry: when i start my game as network is update fast so the network player position not smooth so i use the smooth code by photon is work great but network player not give the correct position for other players in scene any Solution will be Great! :)10375963_291156411057933_1423291642716893921_n.jpg



here my code :
using UnityEngine;
using System;
using System.Collections;
  
[RequireComponent(typeof(Animator))]  

//Name of class must be name of file as well

public class LocomotionPlayer : Photon.MonoBehaviour {


    public Animator animator;

	public AudioClip  WalkAudioFile;

    private float speed = 0;
    private float direction = 0;
    private Locomotion locomotion = null;
	bool GotFirstUpdate = false;
	//we have to disable the things on multiplayer other player view so we not view minimap and other thigns 2 time
	public Transform Minimap;
	public Camera ZoomCamera;
	public Camera camera;
	void Awake()
	{
		if (!photonView.isMine)
		{
			//We aren't the photonView owner, disable this script
			//RPC's and OnPhotonSerializeView will STILL get trough but we prevent Update from running
			Minimap.active = false;
			enabled = false;
			ZoomCamera.enabled = false;
			camera.enabled = false;
		}
	}



	// Use this for initialization
	void Start () 
	{

						animator = GetComponent<Animator> ();
						locomotion = new Locomotion (animator);
	}
    

	Vector3 realPosition = Vector3.zero;
	Quaternion realRotation = Quaternion.identity;
	void Update () 
	{
		if (!photonView.isMine)
		{
			//Update remote player (smooth this, this looks good, at the cost of some accuracy)
			transform.position = Vector3.Lerp(transform.position, realPosition, 0.01f);
			transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.01f);
		}

		if (photonView.isMine) {
						if (animator) {
								JoystickToEvents.Do (transform, this.transform, ref speed, ref direction);
								locomotion.Do (speed * 6, direction * 180);
						}

						if (speed >= 0.3) {
								if (!audio.isPlaying) {

										audio.clip = WalkAudioFile;
										audio.Play ();
								}
				
						}


						if (speed == 0) {
								audio.Pause ();
						}
				}



				
	}
	


	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			//Executed on the owner of this PhotonView; 
			//The server sends it's position over the network
			
			stream.SendNext(transform.position);//"Encode" it, and send it
			stream.SendNext(transform.rotation);//"Encode" it, and send it
			stream.SendNext(transform.localScale);//"Encode" it, and send it
			stream.SendNext(animator.GetFloat("Speed"));
			stream.SendNext(animator.GetFloat("Direction"));

		}
		else
		{
			//Executed on the others; 
			//receive a position and set the object to it

			realPosition  = (Vector3)stream.ReceiveNext();
			transform.rotation = (Quaternion)stream.ReceiveNext();
			transform.localScale = (Vector3)stream.ReceiveNext();
			animator.SetFloat("Speed", (float)stream.ReceiveNext());
			animator.SetFloat("Direction", (float)stream.ReceiveNext());

			if(GotFirstUpdate == false) {
				transform.position = transform.position;
			transform.rotation = transform.rotation;
				animator.SetFloat("Speed",speed);
				GotFirstUpdate = true;
			}

		}
	}



}

Comments

  • *bumb*

    also in facebook they say they have the same problem with smooth is that mean there no solution for that or what :(
  • Hi,
    Try to log transform.position and realPosition on owner and other client. This will show which values are wrong.
    Also note that you set non-owner's transform.rotation to Quaternion.identity on each Update() since realRotation is never changed.