Lerping to Smooth Network Movement
I'm trying to make a simple multiplayer game, mainly following a tutorial as I'm new to unity, but changing some things. But the tutorial was made with an older version of Unity, though that may not be the problem. I'm using PUN and having trouble with smoothing the movement. I'm using Lerp to do this, but instead of spawning at the spawnpoint like I was, I'm spawning somewhere random. not even on the map, but below it, and moving seemingly randomly. I'm in Unity 5. This is my code (C#):
using UnityEngine; using System.Collections;
public class NetworkMoveScript : Photon.MonoBehaviour { Vector3 realPos=Vector3.zero; Quaternion realRot=Quaternion.identity; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
if (photonView.isMine)
{
//idgaf
}
{
transform.position = Vector3.Lerp(this.transform.position, realPos, .1F);
transform.rotation = Quaternion.Lerp(this.transform.rotation, realRot, .1F);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
realPos = (Vector3)stream.ReceiveNext();
realRot = (Quaternion)stream.ReceiveNext();
}
}
}
Your answer
Follow this Question
Related Questions
Unity Photon doesn't Spawn Player 0 Answers
How to improve voice quality in Photon Voice? 1 Answer
Player is lerping from a spawn point in photon ? 0 Answers
Photon team assignment 1 Answer