PUNBasic tutorial and PhotonView.isMine

Options
The code below confuses me as I feel it should be the other way round?
private void OnTriggerEnter(Collider other) {

	if (!photonView.isMine) {
                  return;
	}

	if (!other.name.Contains("Beam")) {
                  return;
	}

	health -= 0.1f;
}
so if this code runs on player1 should it not be if (photonView.isMine) instead?

If player1 beam is hitting itself then if (photonView.isMine) then return, but if player2 beam is hitting player1 then if (photonView.isMine) would be false and so decrease health?

Mental block ....!!




Comments

  • Hi @piginhat,

    you need to note that this code is processed on each client, because each client that is connected to the same room has a copy of the character. Since we are reducing health in this case, we make sure, that this only happens on the client who is the owner of the character which got hit by adding this condition. If we wouldn't have this condition, every client in the room would reduce this character's health. In this example that wouldn't be a big problem because the health value gets synchronized with OnPhotonSerializeView, but if you have a scenario where you only send values like 'Damage Taken' for example, clients may run out of sync over time.
  • piginhat
    Options
    Thanks, yes I think not seeing wood for the trees and trying to get my head around the whole networking thing comes to mind.

    Thanks