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 Jakeo Spikez · Apr 22, 2013 at 11:03 AM · cameranetworkingmultiplayer

Networking Camera not attaching to instantiated object

Hello, I am in the process of trying to convert my camera system from single player to multiplayer. It works great if I connect one user to the server, but once I add in anymore users, the camera seems to attach itself to the first user's version of the game object. Individual movements are controlling their respected characters and they still rotate and move around properly, just the camera is always attached to the first user connected.

This code is from my TP_Camera script.

 public static void UseExistingOrCreateNewMainCamera()
     {
         GameObject tempCamera;
         GameObject targetLookAt;
         TP_Camera myCamera;
         
         if(Camera.mainCamera != null)
         {
             tempCamera = Camera.mainCamera.gameObject;
         }
         else
         {
             tempCamera = new GameObject("Main Camera");
             tempCamera.AddComponent ("Camera");
             tempCamera.tag = "MainCamera";
         }
         
         tempCamera.AddComponent("TP_Camera");
         myCamera = tempCamera.GetComponent ("TP_Camera") as TP_Camera;
         targetLookAt = GameObject.Find("targetLookAt") as GameObject;
         
         myCamera.TargetLookAt = targetLookAt.transform;
     }

Here is where it is called from the TP_Controller script.

 void Awake() 
     {        
         if(networkView.isMine == true)
         {
             CharacterController = GetComponent ("CharacterController") as CharacterController;
             Instance = this;
             TP_Camera.UseExistingOrCreateNewMainCamera();
         }
         else
             enabled = false;

I am fairly certain that it is occurring because every instance is looking for the first game object "targetLookAt" rather than the child of its instance, but everything I've tried either leads to more problems or just doesn't work.

I did get the network camera to follow the proper instances when I created a simple new camera and had it attach to a transform through transform.FindChild() instead of a game object, but trying to do that within the UseExistingOrCreateNewMainCamera function didn't attach the camera to anything at all.

The myCamera.TargetLookAt = transformHereInsteadOfGameObject; line either didn't attach itself to the transform or transformHereInsteadOfGameObject = transform.FindChild("targetLookAt"); didn't work.

Any tips on the best way to solve this? Thank you.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jakeo Spikez · Apr 23, 2013 at 07:19 AM

I figured it out, if anyone else runs into the same problem, here's what I did.

It was indeed because myCamera.TargetLookAt = targetLookAt.transform; was grabbing the first player connected's targetLookAt game object.

My TP_Camera script is attached to my camera and my TP_Controller script is attached to my player prefab. I had to find the child in TP_Controller then bring that into the UseExistingOrCreateNewMainCamera function as a parameter. Setting the value of the transform myCamera.TargetLookAt to a transform that was attached to the child "targetLookAt" of my character properly followed the respective instance of players.

From my TP_Controller script

 void Awake() 
     {        
         if(networkView.isMine == true)
         {
             Transform targetLookAtTransform = transform.FindChild ("targetLookAt");
             CharacterController = GetComponent ("CharacterController") as CharacterController;
             Instance = this;
             TP_Camera.UseExistingOrCreateNewMainCamera(targetLookAtTransform);
         }
         else
             enabled = false;

From my TP_Camera script

 public static void UseExistingOrCreateNewMainCamera(Transform targetLookAtTransform)
         {
             GameObject tempCamera;
             TP_Camera myCamera;
             
             if(Camera.mainCamera != null)
             {
                 tempCamera = Camera.mainCamera.gameObject;
             }
             else
             {
                 tempCamera = new GameObject("Main Camera");
                 tempCamera.AddComponent ("Camera");
                 tempCamera.tag = "MainCamera";
             }
             
             tempCamera.AddComponent("TP_Camera");
             myCamera = tempCamera.GetComponent ("TP_Camera") as TP_Camera;
             
             myCamera.TargetLookAt = targetLookAtTransform;
         }
Comment
Add comment · Share
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
avatar image
0

Answer by Master Tanker · Aug 06, 2013 at 12:13 AM

Hi, im having the same problem that you, im trying to get working your code but im having errors, did you added more Networview component to something else?

May i see your complete code?

what components did you added to your character prefab? im working over "worker demo" modifiying ThirdPersonNetwork.cs and adding a photonview component.

There is some way to contact you Jakeo Spikez?

Comment
Add comment · Share
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

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

13 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

Related Questions

Unity networking tutorial? 6 Answers

Simple Camera look script (MULTIPLAYER) 0 Answers

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

How to trigger camera capture on each player in Unity Networking? 0 Answers

camera layer issue, multiplayer. 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