How do i correctly use Photon.Destroy

Options
Hi, I've been running into a weird issue when the player dies, and it only happens when the player is running really fast and runs into spikes.

Issue: When running really fast the player occasionally will skim over a spike (tip of spike is leveled with the ground). Most of the time the player that ran over the spike dies, but occasionally the other player randomly dies too.

On my Spike game object i have the following code:
private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "Player")
        {
            if (MainMenu.singleORmulti.Equals("multi"))
            {
                PlayerControlsNet.speed = 0.1f;
                PlayerControlsNet.initialTap = true;
                mm.StartCoroutine("Dead");
                iTween.ShakePosition(Camera.main.gameObject, iTween.Hash("x", 0.1f, "y", 0.12f, "time", 0.15f));
                audMan.PlaySoundFx("Pierced"); // sound of death from spike
            }
        }
    }

The coroutine calls the following method
public IEnumerator Dead()
    {
        if (MainMenu.myPhotonView.gameObject != null)
        {
            player = MainMenu.myPhotonView.gameObject;
        }

        PlayerControlsNet.speed = 0.1F;
        PlayerControlsNet.isDead = true;
        PhotonNetwork.Destroy(player);

        yield return new WaitForSeconds(1F);

        if (PlayerControlsNet.isDead == true)
        {
            GameObject hero = PhotonNetwork.Instantiate(RoomManager.curCharacter, new Vector3(RoomManager.playerID * 0.5f, 0f, 0f), Quaternion.identity, 0) as GameObject;
            MainMenu.myPhotonView = hero.GetComponent<PhotonView>();
            player = MainMenu.myPhotonView.gameObject;
            PlayerControlsNet.isDead = false;
        }
    }


Should i just use RPC's and use Destroy instead of PhotonNetwork.Destroy

Please help!
Thank you!

Comments

  • Tobias
    Options
    Do you have to destroy and re-create the player? You could simply mark it as dead and then revive it.
    That would be lighter on resources.
    You can send an RPC or you can sync your state with OnPhotonSerializeView()...