Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by _Grim_ · Jun 26, 2016 at 06:03 AM · photonmultiplayer-networkingpun

PUN : Issue in playing over across Continents

Hello guys, I just started playing around with PUN like a few days ago and made a simple multiplayer tank shooting game , it works perfectly when I test it with my friends around my city , but when I asked my friend from US (I am from india) to give it a go it had problems , like only one of us could see other player , no matter how many times we restarted the game , and in the Editor I could see all three tanks just fine, is this a common issue or maybe I am doing something wrong ? (I am following the Unity Multiplayer FPS Tutorial Using Pun)

the weird thing is Missile/Bullet which is instantiated by the tank is visible to both the players and is syncing its position fine , just not the tanks.

I am just syncing the movement across using a lerp function as the documentation states. TankNetworkMover Script :

 using UnityEngine;
 using System.Collections;
 using UnityStandardAssets.CrossPlatformInput;
 using UnityEngine.UI;
 
 
 
 public class TankNetworkMover : Photon.MonoBehaviour {
     public delegate void Respawn(float time);
     public event Respawn RespawnMe;
     Vector3 position;
     Quaternion rotation;
     float smoothing = 10f;
     [Range(2,100)]
     public float minimumForce = 5;
     [Range(20,300)]
     public float maxForce = 50;
     public float chargeSpeed = 2;
     public float currentForce ;
     public float minUpThrust = 50;
     public float maxUpThrust = 300;
     public float currentUpThrust  ;
     public GameObject missilePoint;                                //missile spawn point
     public GameObject cam;                                
     GameObject Power;                                             //power UI bar
     Image powerUp;                                                // image attached to power            
     public float Health = 100;
     public Image healthGameObject;
     public float shootDelay = 1.5f;
     bool canShoot = true;
     GameObject shootButton;
 
 
 
 
     void Start () {
         Invoke ("FindHealthBar", .4f);
 
         if (photonView.isMine) {
             GetComponent<Rigidbody>().useGravity = true;
             GetComponent<TankCharacterController> ().enabled = true;
             gameObject.tag = "me";
         
             Power = GameObject.FindGameObjectWithTag("power");
             cam = GameObject.FindGameObjectWithTag("camera");
             shootButton = GameObject.FindGameObjectWithTag("shoot");
 
             cam.GetComponent<CameraControl> ().myTank = this.gameObject;
             cam.transform.position = transform.position;
 
             powerUp = Power.GetComponent<Image> ();
             Invoke ("FindMissileSpawnPoint", .2f);
             Invoke ("changeColorRed", .41f);
 
 
         
 
         }
         else{
             StartCoroutine("UpdateData");
             gameObject.tag = "other";
             Invoke ("changeColorBlue", .41f);
 
         }
 
     }
 
 
 
     IEnumerator UpdateData()
     {
         while(true)
         {
             transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * smoothing);
             transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * smoothing);
 
             yield return null;
         }
     }
 
     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         if(stream.isWriting)
         {
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
             stream.SendNext (Health);
         
         }
         else
         {
             position = (Vector3)stream.ReceiveNext();
             rotation = (Quaternion)stream.ReceiveNext();
             Health = (float)stream.ReceiveNext ();
         
         }
     }
 
      void Update()
     {
         
 
         if(CrossPlatformInputManager.GetButtonUp("Shoot") && canShoot && photonView.isMine)
             {
             
             GameObject    missile = PhotonNetwork.Instantiate("Missile",missilePoint.transform.position,missilePoint.transform.rotation,0);
             missile.GetComponent<Rigidbody> ().velocity = transform.forward * currentForce ;
             missile.GetComponent<Rigidbody> ().AddForce(transform.up * currentUpThrust );
             StartCoroutine (ShootDelay (shootDelay));
             canShoot = false;
 
 
             currentForce = minimumForce;
             currentUpThrust = minUpThrust;
             powerUp.fillAmount = 0;
 
             }
         if (CrossPlatformInputManager.GetButton ("Shoot") && canShoot && photonView.isMine) {
             if(currentForce<maxForce)
                 currentForce ++;
             if(currentUpThrust < maxUpThrust)
                 currentUpThrust += 5;
         
             powerUp.fillAmount = Mathf.Lerp (0, 1, Mathf.InverseLerp (minimumForce, maxForce, currentForce));     // UI red power Slider
         }
     }
 
     IEnumerator ShootDelay(float timer)
     {
         shootButton.GetComponent<Image> ().CrossFadeAlpha (.1f, 0, true);
         shootButton.GetComponent<Image> ().CrossFadeAlpha (1, timer, true);
 
         yield return new WaitForSeconds (timer);
         canShoot = true;
     }
 
 
     void FindMissileSpawnPoint()
     {
         missilePoint = GameObject.FindGameObjectWithTag("missilePoint");
 
     }
     void FindHealthBar()
     {
         //healthGameObject = GameObject.FindGameObjectWithTag("health");
         Image[] img = GetComponentsInChildren<Image>();
             foreach(Image i in img)
             {
             if (i.type == Image.Type.Filled)
                 healthGameObject = i;
             }
 
     }
 
     void changeColorRed( )
     {
         healthGameObject.color = Color.red;
     }
 
     void changeColorBlue( )
     {
         healthGameObject.color = Color.blue;
     }
 
     [PunRPC]
     public void ApplyDamage(float damage)
     {
         Health -= damage;
         if(Health<=0 && photonView.isMine)
         {
             if(RespawnMe != null)
                 RespawnMe(3f);
             
             PhotonNetwork.Instantiate ("Explosion", transform.position, transform.rotation, 0);
             PhotonNetwork.Destroy (gameObject);
         }
         healthGameObject.fillAmount = Health / 100;
 
     
     }
 
     //to do
 
 
 }

MissileNetworkMover Script :

 sing UnityEngine;
 using System.Collections;
 
 public class MissileNetworkMover : Photon.MonoBehaviour {
     
     Vector3 position;
 
     float smoothing = 10f;
     // Use this for initialization
     void Start () {
         if (photonView.isMine) {
             GetComponent<Missile>().enabled = true;
 
         }
         else{
             StartCoroutine("UpdateData");
     
 
         }
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     IEnumerator UpdateData()
     {
         while(true)
         {
             transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * smoothing);
         
             yield return null;
         }
     }
 
     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         if(stream.isWriting)
         {
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
 
         }
         else
         {
             position = (Vector3)stream.ReceiveNext();
         
 
         }
     }
 
 }

Network Manager Script :

 using System.Collections;
 using UnityEngine.UI;
 
 public class NetworkSetup : MonoBehaviour {
 
     public Text connectionText;
     public Transform[] spawnPoints;
     public Camera Cam;
     GameObject player;
     // Use this for initialization
     void Start () {
         PhotonNetwork.logLevel = PhotonLogLevel.Full;
         PhotonNetwork.ConnectUsingSettings ("1.0");
     }
     
     // Update is called once per frame
     void Update () {
         connectionText.text = PhotonNetwork.connectionStateDetailed.ToString ();
     }
 
 
     void OnJoinedLobby()
     {
         RoomOptions ro = new RoomOptions (){isVisible = true, maxPlayers = 10};PhotonNetwork.JoinOrCreateRoom ("Mike", ro, TypedLobby.Default);
     }
     void OnJoinedRoom()
     {
         StartSpawnProcess (0f);
     }
 
     void StartSpawnProcess (float respawnTime)
     {
         
         StartCoroutine ("SpawnPlayer", respawnTime);
     }
 
     IEnumerator SpawnPlayer(float respawnTime)
     {
         yield return new WaitForSeconds(respawnTime);
 
         int index = Random.Range (0, spawnPoints.Length);
         player = PhotonNetwork.Instantiate ("Tank", 
             spawnPoints [index].position,
             spawnPoints [index].rotation,
             0);
         player.GetComponent<TankNetworkMover> ().RespawnMe += StartSpawnProcess;
 
     }
 }
 

Thanks.

p.s Please excuse any stupid things in my code , I am not a programmer :p

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Photon Pun 2 "using photon.pun" not working. 8 Answers

Using photon for multiplayer. Button appears for everyone. But it should only appear for the player who has entered the collider. 0 Answers

Photon RPC is not working in photon? 2 Answers

Spawn point for specific player.Photon Pun2 0 Answers

Cannot Instantiate Player on PhotonNetwork 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges