i'm having some troubles in my first, simple, multiplayer racing game, using Photon and Unity. Following classic photon tutorial i've written the code below, but, it won't work properly. In particular there are any smooth movement and "other" player car continue to appear and disapper... maybe i could post a video.
void Update() {
if (gsAppSettings.gameType == Enumerators.GameType.MultiPlayer) {
if (pv.isMine) { //pv is PhotonView
GetPlayerInput ();
WeaponsManagement ();
} else {
SyncMovement ();
}
}
else if (gsAppSettings.gameType == Enumerators.GameType.SinglePlayer) {
GetPlayerInput ();
WeaponsManagement ();
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting) {
if (photonView.isMine) {
stream.SendNext (transform.position);
stream.SendNext (transform.rotation);
stream.SendNext (rb.velocity);
}
} else {
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
currentVelocity = (Vector3)stream.ReceiveNext();
updateTime = Time.time;
}
}
private void SyncMovement() {
Vector3 projectedPosition = this.correctPlayerPos + currentVelocity * (Time.time - updateTime);
transform.position = Vector3.Lerp (transform.position, projectedPosition, Time.deltaTime * 4);
transform.rotation = Quaternion.Lerp (transform.rotation, this.correctPlayerRot, Time.deltaTime * 4);
}
EDIT: This is video. As you can see, the low car is "flipping" up and down https://www.youtube.com/watch?v=QKpYl7C5rl0&feature=youtu.be
correctPlayerPos?
Also a video of the problem would be useful :) \$\endgroup\$