How do you smooth the movement of locally instantiated characters?

Options
When two players connect their movements are jagged and not smooth. I'm currently using this code and it is the one observed in the Photon View.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class NetworkCharacter : Photon.MonoBehaviour {
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
// Use this for initialization
void Start () {
if (photonView.isMine) {

} else {
transform.position = Vector3.Lerp (transform.position, realPosition, 0.1f) ;
transform.rotation = Quaternion.Lerp (transform.rotation, realRotation, 0.1f);
}

}

// Update is called once per frame
void Update () {

}

void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
Debug.Log ("Sending Position");
if (stream.isWriting) {
//our player, need to send position
stream.SendNext (transform.position);
stream.SendNext (transform.rotation);
Debug.Log ("Sending Position");

} else {
//other player, need to receive position.
realPosition = (Vector3) stream.ReceiveNext ();
realRotation = (Quaternion)stream.ReceiveNext ();
Debug.Log ("Receiving Position");
}

}
}

Comments

  • OneManArmy
    Options
    public float smoothPos = 5.0f;
    public float smoothRot = 5.0f;

    transform.position = Vector3.Lerp (transform.position, realPosition, Time.deltaTime * smoothPos) ;
    transform.rotation = Quaternion.Lerp (transform.rotation, realRotation, Time.deltaTime * smoothRot);