I’m stuck trying to solve the shooting system over the network.
I’m using a pool of bullet-objects already instantiated for performance and the bullets can change (increase it damage) if the player wants to.
I can’t figured out the best way to communicate the instances over the network.
One option I’m thinking is that the owner shoots and in the other side a fake bullet is fired. (the owner computes the damage and sends it with RPC). The drawback is that if in the other side the gun is not pointing correctly the player will see that bullet shouldn’t hit him.
Other option is having a NetworkView component on each bullet, and keep them synced (position, rotation, components, vars)
Is it too much if I put a NetworkView component in each bullet? Because could be easily 200 bullets flying around and I don’t if it will be an overhead for the network.
If you want physical bullets, as in rigidbodies, you should let the player who fires them do all the calculations for whom he hit, where he hit, etc. since you can’t reliably replicate them on another client or the server.
The remote clients/server should just get a single bit which says “player X is firing his weapon” and then just play the shoot FX on that player with whatever weapon they have equiped atm.
I use a raycast shooting system. Performance-wise, I think raycasts are way more efficient than using actual bullets.
What I do is cast a ray from my player and detect whether it’s hitting an enemy in the game. If it is and we’re shooting then I get the enemy’s Photon networkView and send a RPC:
var pv = hit.collider.gameObject.GetComponent(PhotonView);
pv.RPC("ApplyDamage",PhotonTargets.All,weaponDamage);
Then on the enemy’s health script, I execute the ApplyDamage function :
@RPC
function ApplyDamage(weaponDamage : float){
health -= weaponDamage;
}