Smooth movement of non-player objects/vehicles over the network? (Photon)

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;
			}
			
		}
		
	}
}

As you are moving a vehicle I bet you are moving it with physics then you should also serialize the rigidbody.velocity. That should solve the chopines problem. About your other issue… Try calling SpawnMyVehicle() from inside OnJoinedRoom() insted of OnCreatedRoom() since that is only called by the masterclient.

My problem with this is that you can’t sync player gameobject transforms directly. If you were able to parent the player to the mount point, and cut their pos/rot sync. It would be perfect. I also disable character controller on anyone but my player. As well as u tagged vs player tag, only on me. It works quite well.

If I don’t think up a way to trick clients into seeing others parenting to vehicles. I will probably delete and spawn new prefabs on entering/editing. May be less code and way more stable.