General advice on structure

Hi,
Are there any best practices for handling damage/effects? i.e. when players do damage to NPCs and/or other players:

1) Where is the best place to track health? On masterclient, then sync back down to each client?
2) Where do I instantiate display effects, caused as a result of damage (i.e. if an NPC gets set on fire) - do I instantiate the "flames" prefab on the client that shot the NPC, then sync and reparent it on all other clients? Or should this also go via masterclient (e.g. when syncing the health back to all clients, send info about the "flames" prefab and instantiate/parent it locally on every client)
3) When creating effects, is it best to PhotonNetwork.Instantiate and then parent the resulting object on every client (to the NPC getting burned). Or just use a regulare Instantiate and do the parenting. Bit confused over the pros/cons here.

I suppose I'm looking for a good structure that cuts down network calls and code complexity, keeps the game responsive and if possible, reduce cheating, etc.


Thanks!

Comments

  • Hi @Keaneo,

    1) Where is the best place to track health? On masterclient, then sync back down to each client?


    If you are targeting the game running in the Cloud, it's best to use the MasterClient for this as he's most likely the one to also handle those game objects (moving, attacking and so on). This would be different if you plan to use server-side custom logic, which is possible on the Enterprise Cloud or when hosting the server on your own. For now I assume that you are using the 'normal' Photon Cloud and therefore I recommend you using the MasterClient for such actions. To synchronize health for example, the MasterClient can use RPCs on the certain game object. If another client wants to damage the object for example. he can use a RPC on that object as well, but only send it to the MasterClient which can be done by using the PhotonTargets.MasterClient. This way the MasterClient can also verify the action which has been made and 'reply' to it. This however might add some lag to the game - you have to check if you are still fine with it.

    2) Where do I instantiate display effects, caused as a result of damage [...]


    You can use another RPC for that. For example something like "ApplyFlameEffect" which is sent to all clients. Whenever a client receives those RPC call, he can instantiate the certain effect locally for himself. To end this effect, you can either send a duration value (how long this effect remains on the target) within the first RPC and let the clients end the effect on their own, or you can send another RPC like "EndFlameEffect".

    3) When creating effects, is it best to PhotonNetwork.Instantiate and then parent the resulting object on every client (to the NPC getting burned). Or just use a regulare Instantiate and do the parenting. [...]


    Do not use Network Instantiation for those. Instead use 'normal' Instantiation on each client.
  • Thanks - there aren't many articles/videos about this kind of thing and it's good to get some advice!
Sign In or Register to comment.