Best way to control a shell (bullet)
Hi all,
I have a set of tanks working nicely in a networked setup. Because tanks fire shells, I have to rely on shells and collision detection instead of raycasting, but I've run into difficulties:
I have set up the shell as gameobject with rigidbody with a Photon View and Photon Transform View - but have deselected synchronise options so no extra network traffic is sent.
I instantiate this shell (when client presses firebutton) using PhotonNetwork.Instantiate (works good)
I allow the clients to control the shell (rigid body is given force when shell is instantiated with a shell control script) which works good.
I then check for collisions on the shell control script - if the shell hits a tank (tagged), I get the photonView of the collider object , I do an RPC call to it (the tank) and deal damage which works ok.
I then instantiate an explosion from the shellscript using PhotonNetwork.Instantiate, then destroy the shell calling Destroy(gameObject)
The explosion destroys itself with a script attacched that calls Destroy (gameObject) after 3 secs.
Two problems:
Sometimes two explosions are instantiated - I am breaking out of foreach loop as soon as I find a tank collision, then Instantiating the explosion (using Photon.Instantiate) , then destroying the shell using Destroy (gameObject);
I know there is a better way of doing this and my code has become a bit messy, but hoping someone has found a good way to:
- spawn bullets that are controlled by clients (to keep network traffic down)
- know what object they've hit (by checking tag and then getting its photonView)
- calling an RPC for that object to tell it the player who shot the shell/owned the shell
Scripts attached:
Movement - which is on tank and has RPC calls
shellCOntrolNilNetowrk - shell control script (bad name I know)
Destroy Explosion - sits on Explosion to kill object after 3 secs or so (not sure if this needs to be PhotonNetwork Destroy or just Destroy)
Rigidbody on Shell is set to continuous