- Home /
PhotonNetwork and Vector3.Lerp resets the player back to (0, 0, 0)
EDIT: NEVERMIND! I found it! The error was in the OnPhotonSerializeView function; I didn't change the transform.rotation and transform.position values to realRotation and realPosition!
Hi Unity. I'm having a bit of a problem with my script. If I have two clients running at the same time, the other player on the first client is shown to have reset their position, going back to (0, 0, 0). This is my code:
using UnityEngine;
using System.Collections;
public class NetworkCharacter : Photon.MonoBehaviour {
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (photonView.isMine) {
//Do nothing
}
else {
transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
Debug.Log ("View is Serialized");
if(stream.isWriting) {
//Our player
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else {
//someone else's player
transform.position = (Vector3)stream.ReceiveNext();
transform.rotation = (Quaternion)stream.ReceiveNext();
}
}
}
Answer by prof · Dec 19, 2013 at 01:34 AM
Because your realPosition always = Vector3.zero; replace trasform at 39 and 40 lines to realPosition
Your answer
Follow this Question
Related Questions
Smooth movement of non-player objects/vehicles over the network? (Photon) 2 Answers
Using lerp to smooth network movement causes rubber banding 1 Answer
Photon Unity Networking (Viking Demo) Error: Argument is out of range. 1 Answer
Networking already instantiated assets 1 Answer
Photon Virtual Joystick won't work after another player has joined the network...? 1 Answer