I have car racing game in development. I want to adapt multiplayer feature to my game. Now I have my car as a prefab and the car is spawned as a clone. My car prefab contains PhotonView(script) and in the observe field I have putted my cars prefab transform. The networking is working, I can get two clones driving. The problem is that the player wont see other players wheels visualy spin and wont see visualy stear when the car is turning. How to achieve that wheels are spinning and turning (stearing) ? My car prefab contains children which are car chassis object, all wheel objects, colliders. I tryed to add PhotonView to wheels but nothing change. Maybe thats becouse I added the PhotonView to the children, but the whole prefab PhotonView overrides other children PhotonViews ?
Based on that you should be able tell how fast the wheels should be spinning. You could send the rotation of the wheels with your updates and then interpolate them locally.
Overall send the information needed and then handle it locally.
How to correctly get stream from PhotonVIew which is added to Wheels ? I now have this script added to wheels, but no rotation is being sent over the network. Maybe I dont understand correctly do I need Quaternion or some additional function ?
Thanks!
void Start(){
pv = GetComponent<PhotonView>();
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
//we are reicieving data
if (stream.isReading)
{
//receive the next data from the stream and set it to the truLoc varible
if(!pv.isMine){
trueRot = (Quaternion)stream.ReceiveNext();
}
}
//we need to send our data
else
{
//send our posistion in the data stream
if(pv.isMine){
stream.SendNext(transform.rotation);
}
}
}
void Update()
{
if(!pv.isMine){
transform.rotation = Quaternion.Lerp(transform.rotation, trueRot, Time.deltaTime * 9);
}
}
}