Search Unity

Synchronize column movement with final ik in photon

Discussion in 'Scripting' started by CastryGames, Mar 5, 2018.

  1. CastryGames

    CastryGames

    Joined:
    Oct 1, 2014
    Posts:
    77
    everything works perfect, but when I start a multiplayer scene with photon I can not see the movement of the other player's column , but yes the movement and the animations

    this is my code c # :


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using RootMotion;
    using RootMotion.FinalIK;

    public class Sync : Photon.MonoBehaviour
    {
    public Vector3 RealPosition = Vector3.zero;
    public Quaternion RealRotation = Quaternion.identity;

    public Animator anim;

    public AimIK aimIK;

    public Quaternion RealRotation1 = Quaternion.identity;
    public Vector3 RealPosition1 = Vector3.zero;
    public Vector3 RealVelocity1 = Vector3.zero;
    public Vector3 RealVelocity2 = Vector3.zero;
    public Rigidbody rg;

    void FixedUpdate()
    {
    if (!photonView.isMine) {
    rg.position = Vector3.Lerp(rg.position, RealPosition1, 0.04f);
    rg.rotation = Quaternion.Lerp(rg.rotation, RealRotation1, 0.04f);
    rg.velocity = Vector3.Lerp (rg.velocity, RealVelocity1, 0.04f);
    rg.angularVelocity = Vector3.Lerp (rg.angularVelocity, RealVelocity2, 0.04f);
    }

    }
    void Update ()
    {
    if (!photonView.isMine)
    {

    transform.position = Vector3.Lerp (transform.position, RealPosition, 0.04f);
    transform.rotation = Quaternion.Lerp (transform.rotation, RealRotation, 0.0f);
    }
    }
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
    if (stream.isWriting) {

    stream.SendNext (transform.position);
    stream.SendNext (transform.rotation);
    stream.SendNext (rg.position);
    stream.SendNext (rg.rotation);
    stream.SendNext (rg.velocity);
    stream.SendNext (rg.angularVelocity);
    stream.SendNext (anim.GetBool ("IsWalking"));

    } else {

    RealPosition = (Vector3)stream.ReceiveNext ();
    RealRotation = (Quaternion)stream.ReceiveNext ();
    RealPosition1 = (Vector3)stream.ReceiveNext ();
    RealRotation1 = (Quaternion)stream.ReceiveNext ();
    RealVelocity1 = (Vector3)stream.ReceiveNext ();
    RealVelocity2 = (Vector3)stream.ReceiveNext ();
    anim.SetBool ("IsWalking",(bool)stream.ReceiveNext());
    }
    }
    }
     
  2. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    It's hard to say exactly, but try changing Update to LateUpdate? Perhaps your animations are overriding the position of the object.

    Also you are not multiplying your Lerp value by Time.deltaTime, which will result in varying speeds when FPS changes on different machines. Should be
    Code (CSharp):
    1. transform.position = Vector3.Lerp (transform.position, RealPosition, 0.04f * Time.deltaTime);