Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
    
Did you make sure to add this script to the photon view update list? What happens if you simply lerp the position to the correctPlayerPos? Also a video of the problem would be useful :) – Iggy May 13 at 11:25
    
Here there is the video: youtube.com/watch?v=QKpYl7C5rl0&feature=youtu.be – stighy May 13 at 18:26
    
From the video it looks like your projectedPosition is wrong. Again try just setting the position without the fancy lerp / prediction, and see if it helps. – Iggy May 14 at 9:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.