Photon PUN Moving Barrier and Fire/Health Sync Problem

Options
Hello,
There are 2 players who are shooting each other with lasers. And there are infinity continuous moving boxes in the middle.

So players are firing with RPC. Player 1 is master client and player 2 is client. If player 2 shoots and hits player 1, player 1 won't die because what player 1 see is fire bumps on box. Of course this doesn't happens everytime. When fire shooted on gap, and both players see that works perfectly.

How can I solve this?

[PunRPC]
void Fire()
{
nextFire = Time.time + fireRate;
PhotonView.Instantiate (shoot, shootSpawn.position, shootSpawn.transform.rotation);
}


Comments

  • Tobias
    Tobias admin
    edited July 2015
    Options
    On networked clients, the situation in the game is not always the exact same, due to lag (as most common cause). So every relevant decision that the game depends on, has to be synced at some point, to make sure everyone "gets it".

    In your case: Per bullet, one player has to detect if it's a hit or miss. This has to be sent to the others, too.
    The shooting player could detect the hit and if it does, it can send another message to reduce the health of the hit player.

    Note: RPCs are not sent immediately when you call them. They get sent when the regular send-interval is up. This is usually sending 10 times/sec. If you need to get rid of a RPCs local lag, you need to call PhotonNetworking.SendOutgoingCommands(). Do this only when necessary, as this affects performance.
  • comolokko
    Options
    Thanks for the answer Tobias. So is this right use of this command?

    void Update(){
    if (Input.GetButton ("Fire1") && Time.time > nextFire && photonView.isMine)
    {
    photonView.RPC ("Fire", PhotonTargets.All);
    PhotonNetwork.SendOutgoingCommands()
    }
    }

    [PunRPC]
    void Fire()
    {
    nextFire = Time.time + fireRate;
    PhotonView.Instantiate (shoot, shootSpawn.position, shootSpawn.transform.rotation);
    }
  • comolokko
    Options
    Oh and I have one more problem. How can I make barriers start moving exactly in same time. Because even a little difference causes the same shooting problem.
  • N1warhead
    Options
    You could always call your side locally and give it a slight delay to get as close as possible to match the same exact timing when the RPC calls finally. But it may not look correctly. But hey whatever works lol
  • Tobias
    Options
    You can take a look at the InRoomRoundTimer script. It's used to time rounds but you can start your barriers based on this as well.