Here is a step-by-step guide to using DestroyIt with MFPS 2.0 for multiplayer destruction.

(1) Import MFPS 2.0 Multiplayer FPS
(2) Open the \MFPS\Scenes\ExampleLevel scene
(3) Import Photon PUN 2 (Free)
(4) Login to Photon Cloud, setup a new Photon PUN project, and copy the AppId into the PUN Wizard

(5) Import DestroyIt
(6) From the top menu, choose Window => DestroyIt => Setup – Minimal

(7) From the \DestroyIt\Demos (safe to delete)\Prefabs\Destructible Objects\Pristine folder, drag the Column prefab into the ExampleLevel scene

(8) Select the Column game object in the Hierarchy and choose Add Component => Photon View
(9) Drag the Column game object to the Observed Components field, and check the Synchronize Position and Rotation checkboxes on the Photon Transform View component

(10) Open the \DestroyIt\Scripts\Behaviors\Destructible.cs script and add the [Photon.Pun.PunRPC] attribute to the ApplyDamage method

(11) Open the \MFPS\Scripts\Weapon\bl_Bullet.cs script and add the section of code below to the OnHit method

DestroyIt.Destructible destObj = hit.collider.gameObject.GetComponentInParent<DestroyIt.Destructible>();
if (destObj != null)
    PhotonView pv = destObj.GetComponent<PhotonView>();
    pv.RPC("ApplyDamage", RpcTarget.All, damage);

(12) Save all your changes to the scripts and the ExampleLevel scene

Note: The instructions provided below are if you want to test multiplayer destruction in your scene with another developer. Each developer on your team will need MFPS 2.0 and DestroyIt and have them imported into the project as outlined in steps 1-5 above.

(13) Export your changes into an asset package. Use CTRL-click to select the ExampleLevel scene and the two scripts you modified, right-click and choose Export Package. Uncheck Include Dependencies so only the modified files are included.
(14) Have your developer friend delete his/her ExampleLevel scene, and import your package so you are both running the same code.
(15) Run the scene, and have your friend also run the scene on their computer. Note that they will also need to use the same Photon AppId as you.
(16) From the in-game menu, create a new server and Join. Your friend should join the other side. Now when either of you damage or destroy the destructible column with a bullet, you will each see progressive damage and the particle effect.

From here, you could expand your damage checking to knife cuts or grenades/molotov cocktails, so those also damage DestroyIt destructible objects. You could also try using a more advanced destructible object, one that has damage effects like smoke or sparks, or one that leaves persistent debris from a destroyed prefab. In the case of persistent debris, you might want to make the debris pieces observable to Photon by adding Photon View components to each of them and syncing the position/rotation. Or you might decide that you like persistent debris but don’t want to worry about syncing each piece with all clients, to save network traffic. It really depends on if the position of each piece of debris is important to track in you game or not. If flying debris can damage players, block movement (ie, a cave collapse), or provide cover, then you probably want to track its position/rotation for all clients.


©Lovatto Studio 2024                                            Privacy Policy | Terms And Conditions


Log in with your credentials


Forgot your details?


Create Account