Sync var

Options
Hello i'm currently working on a tps and i'm facing a little problem.
I have some latency when a player hit another, it take around 1sec for the health to lower, I dunno if I did something wrong could you tell me what do you think about my methods ?

When the bullet hit the player it call a script that handle the damages :
public void touchedByArrow(Arrow arrow) { if (!view.isMine) return; currentHealth -= arrow.damages; if (currentHealth <= 0) { doDie(null); } view.RPC("SyncAll", PhotonTargets.AllBuffered, currentHealth); } [PunRPC] void SyncAll(int hp) { currentHealth = hp; if (currentHealth <= 0) { doDie(null); } }

Am I even doing it right ? x)

Comments

  • Nalik
    Options
    look like i failed the paste

    public void TouchedByArrow(Arrow arrow)
    {

    if (!view.isMine)
    return;
    currentHealth -= arrow.damages;
    if (currentHealth <= 0)
    {
    doDie(null);
    }
    Debug.Log("Arrow Damages :" + arrow.damages);
    Debug.Log("Health left : " + currentHealth);
    view.RPC("SyncAll", PhotonTargets.AllBuffered, currentHealth);

    }

    [PunRPC]
    void SyncAll(int hp)
    {
    Debug.Log("Current health : " + currentHealth + " Health : " + hp);
    currentHealth = hp;
    if (currentHealth <= 0)
    {
    doDie(null);
    }
    }
  • Hi @Nalik,

    I guess this approach seems to be okay so far but one second for the RPC to actually being executed on a remote client is definitively too long. Have you already checked if your connection to the server is okay? One hint therefore is the ping time which you can get by using PhotonNetwork.GetPing();. Does it look okay?