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 Unity3DNewb · Mar 05, 2020 at 12:01 AM · cameranetworkingmultiplayercamera followcamera movement

Trying to follow tutorial to set up Multiplayer camera follow on UNET... and it goes wrong.

Hello! So, I am following this tutorial. It is supposed to teach how to set up a third person camera for Unity multiplayer videogames that use UNET, (I am using Unity2018.2.15f1, so UNET works fine there).

I followed the previous tutorial (which was on different parts of the following code, not the camera part. The other parts work perfectly). But after following the camera follow tutorial, I run the game on one window and it parents a camera to the player, and then, on other window, I create a new player, but it does not create a new camera for the new player. It kind of steals the camera from the previous player and parents it to the new player (I looked on the hierarchy) and it leaves the previous player without a camera. It is weird, because it worked correctly for the person that made the tutorial, but it does not work for me.

The code is assigned to the player prefab.

This is the code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 
 public class SetupLocalPlayer : NetworkBehaviour {
 
 [SyncVar]
 public string pname = "player";
 
 
 
 void OnGUI()
 {
 if(isLocalPlayer)
 {
 pname = GUI.TextField (new Rect (25, Screen.height - 40, 100, 30), pname);
 if(GUI.Button(new Rect(130,Screen.height - 40,80,30), "Change"))
 {
 CmdChangeName(pname);
 }
 }
 }
 
 [Command]
 public void CmdChangeName(string newName)
 {
 pname = newName;
 }
 
     // Use this for initialization
     void Start () {
         
         if(isLocalPlayer)
 GetComponent<PlayerMovement>().enabled = true;
 Camera.main.transform.position = this.transform.position - this.transform.forward*4 + 
                                 this.transform.up*4;
 Camera.main.transform.LookAt(this.transform.position);
 Camera.main.transform.parent = this.transform;
 
 
     }
 
 void Update()
 {
 this.GetComponentInChildren<TextMesh>().text = pname;
 }
 }

(I put the whole code in there just in case it is relevant). Well, to make it less twisted here's the camera part only:

     void Start () {
         
         if(isLocalPlayer)
 GetComponent<PlayerMovement>().enabled = true;
 Camera.main.transform.position = this.transform.position - this.transform.forward*4 + 
                                 this.transform.up*4;
 Camera.main.transform.LookAt(this.transform.position);
 Camera.main.transform.parent = this.transform;
 
 
     }

The channel that uploaded that tutorial does not seem to answer questions anymore, and a ton of people comment that they have the same issue.

I have done a lot of research, and I cannot find a solution to this problem, nor I can find another way of making the camera follow the players that works for me.

I am very new to Unity and programming and (obviously) networking.

If anyone could give me some idea of how to fix this, I would be very grateful!

Thank you for reading this!

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

280 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 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

Unity networking tutorial? 6 Answers

Camera Follow a Target, but not Centered on it 1 Answer

How to change the focus of the camera? 0 Answers

camera follow gameobject moving in angular path. 0 Answers

Camera follow players z axis 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