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 /
  • Help Room /
avatar image
0
Question by Watbadrian · Jul 21, 2016 at 07:13 AM · c#scripting problemmultiplayervrsync

Photon Networking: Moving all players vr

Hello im Adrian and I am having a problem with the Networking part in my game if anyone can tell me what I did wrong or if you can give me some tips that would be awesome.

Here is the NetworkManager script

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
 
     public Camera standbyCamera;
     SpawnSpot [] spawnSpots;
 
     void Start () {
         spawnSpots= GameObject.FindObjectsOfType<SpawnSpot> ();
         Connect ();
 
     }
     
     void Connect () {
         PhotonNetwork.ConnectUsingSettings ("FPS V.0.01");
     }
 
     void OnGUI(){
         GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
     }
 
     void OnJoinedLobby(){
         Debug.Log ("WE joning fam");
         PhotonNetwork.JoinRandomRoom ();
     }
 
     void OnPhotonRandomJoinFailed(){
         Debug.Log ("OnPhotonRandomRoomFailed Fam");
         PhotonNetwork.CreateRoom (null);
     }
 
     void OnJoinedRoom() {
         Debug.Log ("WE JOIN THE ROOM FAM");
 
         SpawnMyPlayer ();
     }
     void SpawnMyPlayer(){
         if(spawnSpots==null) {
             Debug.LogError ("Wah happen!?!?");
             return;
         }
             
         SpawnSpot mySpawnSpot = spawnSpots [ Random.Range(0,spawnSpots.Length)];
         GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("Player1", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
         standbyCamera.enabled = false;
     
         myPlayerGO.GetComponent<SteamVR_ControllerManager>().enabled=true;
         myPlayerGO.GetComponent<MeshRenderer>().enabled=true;
         myPlayerGO.GetComponent<Nettwork>().enabled=true;
 
 
 
 
         myPlayerGO.transform.FindChild ("Controller (left)").gameObject.SetActive (true);
         myPlayerGO.transform.FindChild ("Controller (right)").gameObject.SetActive (true);
         myPlayerGO.transform.FindChild ("Cube").gameObject.SetActive (true);
         myPlayerGO.transform.FindChild ("Camera (head)").gameObject.SetActive (true);
         myPlayerGO.transform.FindChild ("eyevr").gameObject.SetActive (true);
     }
 }
 

Here is the sync script

 using UnityEngine;
 using System.Collections;
 
 public class Nettwork :Photon.MonoBehaviour {
             public GameObject avatar;
             public GameObject righthand;
         public Transform playerGlobal;
         public Transform playerLocal;
           public Transform right;
         public Transform rightl;
 
         void Start ()
         {
             Debug.Log("i'm instantiated");
 
         if (photonView.isMine)
             {
                 Debug.Log("player is mine");
 
                      playerGlobal = GameObject.Find("Camera (head)").transform;
                     playerLocal = playerGlobal.Find("eyevr");
                 this.transform.SetParent(playerLocal);
                 this.transform.localPosition = Vector3.zero;
 
                 playerGlobal.GetComponent<Camera>().enabled=true;
                 playerGlobal.GetComponent<SteamVR_TrackedObject>().enabled=true;
                 playerGlobal.GetComponent<GUILayer>().enabled=true;
 
 
             right = GameObject.Find("Controller (right)").transform;
             rightl= right.Find("Model");
             this.transform.SetParent(rightl);
             this.transform.localPosition = Vector3.zero;
 
             right.GetComponent<SteamVR_TrackedObject>().enabled=true;
             right.GetComponent<ArcTeleporter>().enabled=true;
             right.GetComponent<SteamVR_TrackedController>().enabled=true;
 
             //avatar.SetActive(false);
                 Debug.Log ("IM not on");
         
             }
         }
 
         void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
         {
         if (stream.isWriting)
             {
                 stream.SendNext(playerGlobal.position);
                 stream.SendNext(playerGlobal.rotation);
                 stream.SendNext(playerLocal.localPosition);
                 stream.SendNext(playerLocal.localRotation);
 
             stream.SendNext(right.position);
             stream.SendNext(right.rotation);
             stream.SendNext(rightl.localPosition);
             stream.SendNext(rightl.localRotation);
             }
             else
             {
                 this.transform.position = (Vector3)stream.ReceiveNext();
                 this.transform.rotation = (Quaternion)stream.ReceiveNext();
                 avatar.transform.localPosition = (Vector3)stream.ReceiveNext();
                 avatar.transform.localRotation = (Quaternion)stream.ReceiveNext();
 
             this.transform.position = (Vector3)stream.ReceiveNext();
             this.transform.rotation = (Quaternion)stream.ReceiveNext();
             righthand.transform.localPosition = (Vector3)stream.ReceiveNext();
             righthand.transform.localRotation = (Quaternion)stream.ReceiveNext();
             }
         }
     }


Here is some pictures: So I put the sync script inside the Player1 prefab and added it to the Photonview like this: alt text

And what that should do is sync the players right hand and head and activate everything inside the hands, head, etc:

alt text

And just in case here is how it all looks like: https://drive.google.com/file/d/0B01xDnOShBTVY0NJbkhCeFhHZWc/view?usp=sharing

(Player A is me Player B is the online player) So the problem is when Player B joins first he spawns in and its ok nothing is wrong, but then when Player A joins in he sees Player B and when Player A moves his hand and head, Player B mimics the same. Player B can move his player freely but he can not see anyone else in the scene nor a clone like Player A. When Player A looks down you can see the head of his player but its not moving and the head is in the ground its like Player A is on a separate camera just hovering were he should spawn. When Player B disconnects Player A teleport were Player B was and becomes Player B. When Player B joins back he sees what I was seeing. Sorry if this is a simple thing to fix but I am just a bit of a noob right now with the networking stuff and if this was confusing please feel free to ask for questions or more pictures I will be happy to send them them, and im not sure but I think I did something wrong on the Nettwork script, thank you in advance for reading this really appreciate it :D

pic1.png (45.4 kB)
pic11.png (244.6 kB)
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

232 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SyncVar on Server Object 0 Answers

How to send event to my canvas via script 0 Answers

c# - error CS0103: The name `hit' does not exist in the current context (cardboard switching) 1 Answer

Tetxure swap using HTC controllers 0 Answers

Multiplayer vehicle game - physics or not to physics 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