Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Mischaal · Dec 04, 2012 at 12:48 PM · cameranetworkingthird-person

Unity 3rd Person Camera in Multiplayer

Hey People! I've made a 3rd Person Camera. This worked very well without Player and camera prefabs in a Little prototype. I wanted to integrate my code into my Network game but it hasn't worked yet. The Problem is that the camera is turning around a Point if I use my mouse (so this works fine) but if I move my character the camera doesn't make a move. I'm not sure if this has something to do with my Network code so I'll post both codes here. I hope you're able to help me >_<

Camera Code (attached on my main camera):

 public GameObject target;
     public float rotateSpeed = 5;
     Vector3 offset;
     
     void Start() 
     {
         offset = target.transform.position -   transform.position;
     }
     
     void LateUpdate() 
     {
         if(networkView.isMine)
         {
             float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
             target.transform.Rotate(0, horizontal, 0);
             
             float desiredAngle = target.transform.eulerAngles.y;
             Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
             transform.position = target.transform.position - (rotation * offset);
             
             transform.LookAt(target.transform);
         }
     }


And here is my netowrk code: private bool refreshing = false; private HostData[] hostData; public string gameName = "Network Game"; public float buttonX; public float buttonY; public float buttonWidth; public float buttonHeight; private int i = 1;

     public GameObject playerPrefab;
     public Camera camera;
     public Transform spawnObject;
     public Transform cameraPosition;
     
     // Use this for initialization
     void Start () 
     {
         buttonX = Screen.width * 0.05f;
         buttonY = Screen.width * 0.05f;
         buttonWidth = Screen.width * 0.1f;
         buttonHeight = Screen.width * 0.05f;
     }
     void startServer()
     {
         Network.InitializeServer(12, 25001, !Network.HavePublicAddress());
         MasterServer.RegisterHost(gameName,"Anime Girls vs Mechs", "Anime Girls vs Mechs Game");
     }
     
     void refreshHostList()
     {
         MasterServer.RequestHostList (gameName);
         refreshing = true;
     }
     
     void Update()
     {
         if(refreshing)
         {
             if(MasterServer.PollHostList ().Length != 0)
             {
                 refreshing = false;
                 hostData = MasterServer.PollHostList();
                 Debug.Log (MasterServer.PollHostList ().Length);
             }
         }
     }
     
     void spawnPlayer()
     {
         Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
         Network.Instantiate(camera, cameraPosition.position, Quaternion.identity, 0);
     }
     
     //Messages
     void OnServerInitialized()
     {
         Debug.Log ("Server initialized");
         spawnPlayer();
     }
     
     void OnConnectedToServer()
     {
         spawnPlayer();
     }
     
     void OnMasterServerEvent(MasterServerEvent masterServerEvent)
     {
         if(masterServerEvent == MasterServerEvent.RegistrationSucceeded)
         {
             Debug.Log ("Server Registrated");
         }
     }
     //Draw GUI
     void OnGUI()
     {
         if(!Network.isClient && !Network.isServer)
         {
             if(GUI.Button (new Rect(buttonX, buttonY, buttonWidth, buttonHeight), "Start Server"))
             {
                 Debug.Log ("Server Started");    
                 startServer();
             }
             if(GUI.Button (new Rect(buttonX, buttonY * 1.2f + buttonHeight, buttonWidth, buttonHeight), "Refresh Hosts"))
             {
                 Debug.Log ("Refreshing Hosts");    
                 refreshHostList();
             }
             
             if(hostData != null)
             {
                 foreach(HostData hosts in hostData)
                 {
                     if(GUI.Button (new Rect(buttonX * 1.5f + buttonWidth, buttonY * 1.2f + (buttonHeight * i), buttonWidth * 3f, buttonHeight * 0.5f), hosts.gameName))
                     {
                         Network.Connect(hosts);
                     }
                     if(MasterServer.PollHostList ().Length > i)
                         i++;
                 }
             }
         }
     }

am I doing it wrong or what is the Problem?

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

9 People are following this question.

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

Related Questions

mirror player camera using one camera 0 Answers

Broadcast camera render over network 2 Answers

Multiplayer camera switch issue 0 Answers

How to set up multiple cameras for multiplayer 1 Answer

Lock on opponent in UNET (C#) 1 Answer


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