Weapon Shooting

Options
Hello, I haven't found any answers to this question nor videos on the internet. But I am currently setting up weapon shooting for my co op zombie survival game and I am having issues with syncing the weapon shooting through the network.

Now, the weapon shooting itself works fine. It's just that I don't understand how Photon works and all the animations and effects are not visible for other players. For the players and the zombies I use PhotonView so they are visible for every player. The zombies are fully setup, they target the closest player and are functioning very smoothly and well through the network. It's just that when player 1 shoot I want player 2 to see the shooting animation, the muzzle flash and the impact effect. I have a script attached to the weapon prefab that is instantiated to the player's "Weapon Holder" parent. I was just wondering if I would have to instantiate every single effect using PhotonNetwork.Instantiate.

I tried instantiating the weapon through the Network but that instantiated the weapon into the player's weapon holder parent and also it instantiated one more into the center of the world. This also lead to it so that players that joined later don't see the weapons that the players that joined before have equipped. So in this case if I join after the host, the host won't have a weapon on that player's screen.

I know that this is a super confusing question. I don't care I'm pissed off because I've spent all day try to figure this out and this doesn't work. Please answer this question with a video or documentation on how to sync this. I don't want to give up on this project.

Thanks

Answers

  • Plossom
    Options
    I'm not sure if I got all your problems...
    Well first of all i solved the shooting issue in my project - i'll pick this up later

    First of all the animations not being synchroniesed; well i think nearly everyone knows that position and rotation have to be sent and received else the movement won't be seen by the other player (MarcoPolo Tutorial):

    void Update()
    {
    if (!photonView.isMine)
    {
    transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
    transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
    }
    }

    // Sende Bewegung,Rotation,Animation senden und empfangen
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    if (stream.isWriting)
    {
    // We own this player: send the others our data
    stream.SendNext(transform.position);
    stream.SendNext(transform.rotation);
    //stream.SendNext(anim.GetBool("Run"));
    //stream.SendNext(anim.GetBool("Fire"));
    }
    else
    {
    // Network player, receive data
    this.correctPlayerPos = (Vector3)stream.ReceiveNext();
    this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
    //anim.SetBool("Run", (bool)stream.ReceiveNext());
    //anim.SetBool("Fire", (bool)stream.ReceiveNext());
    }
    }

    as you can see there I once also sent all the bools, floats... and received them - this acctually works fine...
    Just make sure that you don't forget to get the spelling of them right and ofcourse link your animator (public Animator anim;) and of course link the skript to PhotonView and use the Photon.Monobehaviour class.
    So your problem with the animations is acctually solved BUT if you have a lot of animations and you have to keep the track of all the things being sent around, so Photon offers a better way to solve this with "Photon Animator" - a photon unity networking plugin that you can add to any object.
    So add the Photon Animator View Skript to the Object you want to animate. It automatically gets the bools of the Animator attached to this object. Now you can change all the "Disabled" buttons to "Continuous" (Layer & Parameters). This Photon Animator View should be synchronised over the network - so linkt this scipt to the observed components at the PhotonView Script on the player... so now the send and received lines are not annymore needed.
    So these parameters you can normally change via another skript - with the Photon Aimator View script you only send the bools and receive them - so if you change a bool to true via another "normal" script you set the bool to Continuous at its Photon Animator View component which just pays attention on your bools changing and sending these changes via the Network...
    Pay attention that Photon has problems with synchronizing Triggers - so don't use triggers.

    I'have to go to school now but i'll answer you the shooting issue later today ...

    Hope i could help you :)
  • JoiBjeBje
    Options
    I appriciate your time to write this but I actually figured it out and I switched to Photon BOLT.