Hey guys. I finally got a vehicle working in single player but when I try multiplayer the movement looks very choppy. I’m following along quill18’s multiplayer FPS tutorial. My vehicle is instantiated in a setup like this:
void OnCreatedRoom{
SpawnMyVehicle();
}
void SpawnMyVehicle(){
GameObject Vehicle = PhotonNetwork.Instantiate ("Vehicle", vehicleSpawnspot.transform.position, vehicleSpawnspot.transform.rotation, 0);
}
. Quill18’s script instantiates players when they join the room, but I do not want to instantiate a vehicle for every player that enters. I only want it to be instantiated at the beginning of the room’s creation.
Two problems exist. The first is the vehicle deletes itself when the player who created the room leaves. The second is the movement is very choppy for any player that didn’t create the room. Any help would be greatly appreciated. My vehicle script that the photon view follows looks like this:
using UnityEngine;
using System.Collections;
public class NetworkVehicle: Photon.MonoBehaviour {
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
bool gotFirstUpdate = false;
// 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) {
if(stream.isWriting) {
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else {
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
if(gotFirstUpdate == false) {
transform.position = realPosition;
transform.rotation = realRotation;
gotFirstUpdate = true;
}
}
}
}