{"id":2558,"date":"2013-12-28T02:55:12","date_gmt":"2013-12-27T23:55:12","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=2558"},"modified":"2013-12-28T14:52:34","modified_gmt":"2013-12-28T11:52:34","slug":"terravol-photon-networking","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2013\/12\/28\/terravol-photon-networking\/","title":{"rendered":"TerraVol + Photon Networking"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2559\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/12\/28\/terravol-photon-networking\/terravol_photon_multiplayer_1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/terravol_photon_multiplayer_1.png?fit=680%2C478&amp;ssl=1\" data-orig-size=\"680,478\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"terravol_photon_multiplayer_1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/terravol_photon_multiplayer_1.png?fit=300%2C210&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/terravol_photon_multiplayer_1.png?fit=680%2C478&amp;ssl=1\" class=\"alignnone size-full wp-image-2559\" alt=\"terravol_photon_multiplayer_1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/terravol_photon_multiplayer_1.png?resize=680%2C478\" width=\"680\" height=\"478\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/terravol_photon_multiplayer_1.png?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/terravol_photon_multiplayer_1.png?resize=300%2C210&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Had to test it, how it would work if connect <a title=\"http:\/\/forum.unity3d.com\/threads\/177573-TerraVol-volumetric-voxel-terrain-system-Dig-holes-amp-caves-in-your-terrains!\" href=\"http:\/\/forum.unity3d.com\/threads\/177573-TerraVol-volumetric-voxel-terrain-system-Dig-holes-amp-caves-in-your-terrains!\" target=\"_blank\">TerraVol <\/a>with <a title=\"http:\/\/u3d.as\/content\/exit-games\/photon-unity-networking-free\/2ey\" href=\"http:\/\/u3d.as\/content\/exit-games\/photon-unity-networking-free\/2ey\" target=\"_blank\">Photon<\/a>.. Surprisingly it only took few clicks!<\/p>\n<p><strong>Webplayer demo:<\/strong><br \/>\ncoming later<\/p>\n<p><strong>Notes<\/strong><\/p>\n<p>&#8211;\u00a0\u00a0 \u00a0Import\/Open <a title=\"https:\/\/www.assetstore.unity3d.com\/#\/content\/8131\" href=\"https:\/\/www.assetstore.unity3d.com\/#\/content\/8131\" target=\"_blank\">TerraVol <\/a>project (needs to be purchased from assetstore)<br \/>\n&#8211;\u00a0\u00a0 \u00a0Import Photon networking <a title=\"http:\/\/u3d.as\/content\/exit-games\/photon-unity-networking-free\/2ey\" href=\"http:\/\/u3d.as\/content\/exit-games\/photon-unity-networking-free\/2ey\" target=\"_blank\">http:\/\/u3d.as\/content\/exit-games\/photon-unity-networking-free\/2ey<\/a><br \/>\n&#8211;\u00a0\u00a0 \u00a0Setup photon (follow instructions, mainly just enter your appId and press save..)<br \/>\n&#8211;\u00a0\u00a0 \u00a0Open scene \u201cDemoWorker-Scene\u201d (it has lobby system)<br \/>\n&#8211;\u00a0\u00a0 \u00a0From build settings remove everything<br \/>\n&#8211;\u00a0\u00a0 \u00a0Add that \u201cDemoWorker-Scene\u201d scene to build settings as scene 0<br \/>\n&#8211;\u00a0\u00a0 \u00a0Open scene \u201crandom_generate_scene\u201d<br \/>\n&#8211;\u00a0\u00a0 \u00a0Save as new scene \u201cscene_multiplayer\u201d and add it to build settings as scene 1<br \/>\n&#8211;\u00a0\u00a0 \u00a0In the scene \u201cDemoWorker-Scene\u201d select Scripts object from Hierarchy<br \/>\n&#8211;\u00a0\u00a0 \u00a0Open Worker Menu script<br \/>\n&#8211;\u00a0\u00a0 \u00a0Change line:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">public static readonly string SceneNameGame = &quot;DemoWorkerGame-Scene&quot;;<\/pre>\n<p>&#8211;\u00a0\u00a0 \u00a0into:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">public static readonly string SceneNameGame = &quot;scene_multiplayer&quot;;<\/pre>\n<p>&#8211;\u00a0\u00a0 \u00a0Quick test: Press Play (lobby should appear, press Create, Terravol scene should be loaded\u201d<br \/>\n&#8211;\u00a0\u00a0 \u00a0Open \u201cDemoWorkerGame-Scene\u201d<br \/>\n&#8211;\u00a0\u00a0 \u00a0Copy \u201cMain Camera\u201d, \u201cGuiText: Demo Worker\u201d, \u201cScripts\u201d from Hierarchy<br \/>\n&#8211;\u00a0\u00a0 \u00a0Open \u201cscene_multiplayer\u201d and paste those objects there<br \/>\n&#8211;\u00a0\u00a0 \u00a0Disable old \u201cMain camera\u201d (it has the character controller and stuff)<br \/>\n&#8211;\u00a0\u00a0 \u00a0Select scripts object, rename it as \u201cPhotonScripts\u201d<br \/>\n&#8211;\u00a0\u00a0 \u00a0Set \u201cPhotonScripts \u201c Y position to 120 (player is instantiated at this position when connected)<br \/>\n&#8211;\u00a0\u00a0 \u00a0In build settings, switch to Webplayer platform<br \/>\n&#8211;\u00a0\u00a0 \u00a0Player settings, enable: [x] Run in background<br \/>\n&#8211;\u00a0\u00a0 \u00a0Build &amp; Run<br \/>\n&#8211;\u00a0\u00a0 \u00a0Webplayer starts, Lobby: Create Room<br \/>\n&#8211;\u00a0\u00a0 \u00a0Press play in editor, Lobby: Join room<br \/>\n&#8211;\u00a0\u00a0 \u00a0Yay! 2 players in terravol scene..but the terrains are randomly generated..<br \/>\n&#8211;\u00a0\u00a0 \u00a0Not sure if there is some fixed seed option in TerraVol yet.. so:<br \/>\n&#8211;\u00a0\u00a0 \u00a0Open \u201cTerraMap\u201d script<br \/>\n&#8211;\u00a0\u00a0 \u00a0Find:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">tmg.randomize = true;<\/pre>\n<p>&#8211;\u00a0\u00a0 \u00a0Replace with:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">tmg.randomize = false;<\/pre>\n<p>&#8211;\u00a0\u00a0 \u00a0Seems to work, same level on both.<br \/>\n&#8211;\u00a0\u00a0 \u00a0From the old Main Camera, copy Builder script component to the new Main Camera<br \/>\n&#8211;\u00a0\u00a0 \u00a0Can dig the terrain (although it happens under the player?) and its not synced..<br \/>\n&#8211;\u00a0\u00a0 \u00a0Add PhotonView component to MainCamera (View id seems to be 2)<br \/>\n&#8211;\u00a0\u00a0 \u00a0Open the \u201cBuilder\u201d script<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2560\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/12\/28\/terravol-photon-networking\/i-have-no-idea-what-im-doing-dog\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/i-have-no-idea-what-im-doing-dog.jpg?fit=400%2C254&amp;ssl=1\" data-orig-size=\"400,254\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"i-have-no-idea-what-im-doing-dog\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/i-have-no-idea-what-im-doing-dog.jpg?fit=300%2C190&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/i-have-no-idea-what-im-doing-dog.jpg?fit=400%2C254&amp;ssl=1\" class=\"alignnone size-medium wp-image-2560\" alt=\"i-have-no-idea-what-im-doing-dog\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/i-have-no-idea-what-im-doing-dog-300x190.jpg?resize=300%2C190\" width=\"300\" height=\"190\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/i-have-no-idea-what-im-doing-dog.jpg?resize=300%2C190&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/i-have-no-idea-what-im-doing-dog.jpg?w=400&amp;ssl=1 400w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><br \/>\n&#8211;\u00a0\u00a0 \u00a0Find line:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">DoAction( hit );<\/pre>\n<p>&#8211;\u00a0\u00a0 \u00a0Replace with:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">if (hit!=null)\r\n{\r\nPhotonView photonView = PhotonView.Get(this);\r\nphotonView.RPC(&quot;DoAction&quot;, PhotonTargets.All, hit.Value.x,hit.Value.y,hit.Value.z);\r\n}<\/pre>\n<p>&#8211;\u00a0\u00a0 \u00a0Find line:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">public void DoAction (Vector3? point)<\/pre>\n<p>&#8211;\u00a0\u00a0 \u00a0Replace with:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">&#x5B;RPC]\r\npublic void DoAction (float hx, float hy, float hz)\r\n{\r\nVector3? point = new Vector3(hx,hy,hz);<\/pre>\n<p>&#8211; Had to do that with 3 floats, Vector3 or Vector3? was giving some errors when used as rpc parameter.<br \/>\n&#8211;\u00a0\u00a0 \u00a0What is that \u201c?\u201d <a title=\"http:\/\/stackoverflow.com\/questions\/2326158\/why-is-there-a-questionmark-on-the-private-variable-definition\" href=\"http:\/\/stackoverflow.com\/questions\/2326158\/why-is-there-a-questionmark-on-the-private-variable-definition\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/2326158\/why-is-there-a-questionmark-on-the-private-variable-definition<\/a><br \/>\n&#8211;\u00a0\u00a0 \u00a0Check also Photon RPC: <a title=\"http:\/\/doc.exitgames.com\/en\/photon-realtime\/PhotonUnityNetworkingIntro#_rpcpun\" href=\"http:\/\/doc.exitgames.com\/en\/photon-realtime\/PhotonUnityNetworkingIntro#_rpcpun\" target=\"_blank\">http:\/\/doc.exitgames.com\/en\/photon-realtime\/PhotonUnityNetworkingIntro#_rpcpun<\/a><br \/>\n&#8211;\u00a0\u00a0 \u00a0Build, Run, Create..<br \/>\n&#8211;\u00a0\u00a0 \u00a0Editor, Hit Play, Join, Modify terrain!<br \/>\n&#8211;\u00a0\u00a0 \u00a0It works!!1<\/p>\n<p><strong>TODO:<\/strong><br \/>\n&#8211;\u00a0\u00a0 \u00a0Use original FPS\/Character controller<br \/>\n&#8211;\u00a0\u00a0 \u00a0Then that should fix the mousehit point also (currently digging happens around the player..)<br \/>\n&#8211;\u00a0\u00a0\u00a0 What happens when another player is in a different chunk..<br \/>\n&#8211;\u00a0\u00a0 \u00a0Explosions, Cannons, Meteorites..or not.<\/p>\n<p>*******************************************************<\/p>\n<p><strong>Part2 (use terravol original character controller)<\/strong><\/p>\n<p>&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Rename the new Main Camera as \u201cMain Camera Photon\u201d<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Then disable it<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Rename the old Main Camera as \u201cMain Camera TerraVol\u201d<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Then enable it<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Drag &amp; Drop Photon View component from the \u201cMain Camera Photon\u201d into \u201cMain Camera TerraVol\u201d (You could just remove it from the old and add to the new manually also)<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Create new folder in Project window \u201cResources\u201d<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Create prefab from \u201cMain Camera TerraVol\u201d by dragging it from Hierarchy window into that \u201cResources\u201d folder in Project window<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In \u201cPhotonScripts\u201d gameobject, assign that\u00a0 new prefab into Player Prefab field<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In Map gameobject, assign that\u00a0 new prefab into Player Camera \u00a0field (*this could be bad, since its referencing the prefab..not scene object?)<br \/>\n&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Build &amp; Run, test in editor, Seems to work! Just sometimes its digging in wrong direction?<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Had to test it, how it would work if connect TerraVol with Photon.. Surprisingly it only took few clicks! Webplayer demo: coming later Notes &#8211;\u00a0\u00a0 \u00a0Import\/Open TerraVol project (needs to be purchased from assetstore) &#8211;\u00a0\u00a0 \u00a0Import Photon networking http:\/\/u3d.as\/content\/exit-games\/photon-unity-networking-free\/2ey &#8211;\u00a0\u00a0 \u00a0Setup photon (follow instructions, mainly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2559,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[420,3],"tags":[381,380,129,168,567,311],"class_list":["post-2558","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-unity3d","tag-multiplayer","tag-networking","tag-photon","tag-terrain","tag-terravol","tag-voxel"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/12\/terravol_photon_multiplayer_1.png?fit=680%2C478&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-Fg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=2558"}],"version-history":[{"count":11,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2558\/revisions"}],"predecessor-version":[{"id":2574,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2558\/revisions\/2574"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/2559"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=2558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=2558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=2558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}