Hey I have the following problem:
this is my code for network interaction
this controls player syncing:
public class NetworkCharacter : Photon.MonoBehaviour {
Vector3 realposition = Vector3.zero;
Quaternion realrotation = Quaternion.identity;
float lastupdateTime;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(photonView.isMine)
{
}
else
{
transform.position = Vector3.Lerp(transform.position,realposition,0.5f);
transform.rotation = Quaternion.Lerp(transform.rotation,realrotation,0.5f);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
realposition = (Vector3)stream.ReceiveNext();
realrotation = (Quaternion)stream.ReceiveNext();
}
}
}
this controls player connection
public class NetworkManager : MonoBehaviour {
public GameObject standbycamera;
GameObject[ ] spawnspots;
// Use this for initialization
void Start ()
{
spawnspots = GameObject.FindGameObjectsWithTag(“Respawn”);
Connect();
}
void Connect()
{
PhotonNetwork.ConnectUsingSettings(“0.0.3”);
}
void OnGUI()
{
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
}
void OnJoinedLobby()
{
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed()
{
PhotonNetwork.CreateRoom(null);
}
void OnJoinedRoom()
{
spawnmyhero();
}
void spawnmyhero()
{
GameObject myspawnspot = spawnspots[Random.Range(0,spawnspots.Length)];
GameObject myplayergo =(GameObject)PhotonNetwork.Instantiate(“Player”,myspawnspot.transform.position,myspawnspot.transform.rotation,0);
standbycamera.SetActive(false);
myplayergo.GetComponent().enabled = true;
myplayergo.GetComponent().enabled = true;
myplayergo.GetComponent().enabled = true;
//myplayergo.GetComponent().enabled = true;
//myplayergo.GetComponent<Plank_building>().enabled = true;
myplayergo.GetComponent().enabled = true;
myplayergo.GetComponentInChildren().enabled = true;
}
}
I have temporarily fixed the problem by freezing the y position of the rigidbody of the character but that is very undesirable.
please advise