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 Codez · Dec 02, 2017 at 04:00 AM · cameraspawningnetwork.instantiate

Assigning a (main) Camera to Spawned Prefabs

I've been following along the Unity Networking Tutorial (unity3d.com/learn/tutorials/s/multiplayer-networking) and I've been trying to get it so that the main camera follows each local player as they spawn.
How would one go about doing this? I've tried making the prefab have a child camera but it break when another person spawns as the host then sees themselves move through the eyes of the second player, but I've read it's better for this main camera follow approach.
I've also looked at this post (particularly Loahrs reply), but haven't been able to make it work (https://stackoverflow.com/questions/36261871/how-to-attach-the-camera-to-a-player-object-instantiated-by-hlapi-network-manage).

I've been stuck for some time, so any help would be appreciated :)


Update: The CameraFollow().target part of Loahrs code comes up as an error (this is part of the PlayerController script on the player prefab).

 public override void OnStartLocalPlayer() {
         //function is only called for local player
         //Turns local player blue
         GetComponent<MeshRenderer> ().material.color = Color.blue;
         Camera.main.GetComponent<CameraFollow>().target = transform; //Fix Camera on "me"
     }

I'm trying to work out what is wrong with the line but I can't find Unity manuals on it.

Comment
Add comment · Show 2
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 RocketFriday · Dec 10, 2017 at 12:37 PM 0
Share

Have you tried setting the depth of the second camera to a different number?

avatar image Codez · Dec 11, 2017 at 08:47 AM 0
Share

I'm not entirely sure how changing the depth of the main camera would help, as there's only one camera being rendered; it should just locally follow different players (If this is in response to my attempts at having child cameras of the prefab, I was just trying to explain what I've already attempted. I also think the one camera would be easier and better to work with).

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Codez · Dec 15, 2017 at 03:07 AM

Finally found the issue. The reason my code wasn't working was because 'CameraFollow' was trying to access a script of the same name (which mine wasn't) and the '.target()' referencing a function within the 'CameraFollow' script.

A helpful link to anyone else stuck: https://answers.unity.com/questions/1157437/making-my-camera-follow-player-in-multiplayer.html

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 Edgar_94_ · Dec 15, 2017 at 01:25 AM

The best practise I have found is that you have a FPS Player with a camera integrated in this prefab AND a TPS Player WITHOUT a camera integrated. This way, if a player is not local, you can only see him looking for it in the scene.

I don't know if I have explained well, but here is an schematic:

3rd person prefab with no camera -> Remote Player 1st person prefab with camera -> Local Player

This way you will find it more easy ;)

Comment
Add comment · Show 1 · 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 Codez · Dec 15, 2017 at 02:24 AM 0
Share

I'm not following what you're suggesting... Is the player controlling a 1st person prefab through a 3rd person prefab while viewing the 1st person prefab camera? If so, I'm not sure how this would help. In the context of the Unity Networking Tutorial, what are you saying should be modified?

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

113 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

Related Questions

Help with repositioning object to a random position in the FOV 1 Answer

Calculate distance at which an object occupies 0 pixels, given bounding sphere? 1 Answer

New gameobject to spawn in front of editor camera?, 1 Answer

Unet: Spawner spawns for every player one object instead of just one 0 Answers

Having Trouble with Instantiating an object on an axis 2 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