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 mihailt · Jun 03, 2010 at 09:11 AM · cameramultiplayer

Multiplayer Cameras Problems

Hi, i'm new to unity, i'm playing with racing game tutorial, and trying to add multiplayer capabilities to it, i followed M2H network tutorial, and seem to understand it (to some extent), I'm creating car objects by Network.Instantiate also i modified Car.js, so that car would be controllable only by object owner

function GetInput()
{
    if (networkView.isMine) {
        throttle = Input.GetAxis("Vertical");
        steer = Input.GetAxis("Horizontal");
        CheckHandbrake();
    }
}

and this part seems to work. The problem that each car has a camera object assigned and camera has component CarCamera which needs target and is responsible for changing angles depenging on the car position, and when i create second car and second camera first camera loses it's focus and second one doesn't get one, so as a result while cars are individually controlled game cannot be played, because of that camera issue.

The script i use for instaniating players is:

function SpawnPlayer(){
    var player : Transform = Network.Instantiate(networkCarPrefab, Vector3(860, 102.2085, 878), transform.rotation, 0);
    var camera : Transform = Network.Instantiate(Main_Camera, Vector3(860, 102.2085, 878), transform.rotation, 0);
    var carCamera = camera.GetComponent("CarCamera");
    carCamera.target = player;
}

Would anyone point me into direction i should be digging ? Thx

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
1
Best Answer

Answer by mihailt · Jun 03, 2010 at 04:05 PM

While, Cap provided some usefull insights, that was not the case.

The way i solved the problem, was not to instaniate a seperate camera object for each player, but to use one camera and to assign target for it on each player spawn. so the working code in my case looks like:

function SpawnPlayer(){
    var player : Transform = Network.Instantiate(networkCarPrefab, Vector3(860, 102.2085, 878), transform.rotation, 0);
    var camera = GameObject.Find("Main_Camera");
    var follow = camera.GetComponent("CarCamera");
    follow.target = player;
}

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 Cap · Jun 03, 2010 at 07:36 PM 0
Share

Oh, yea that'd work too heh.

avatar image
1

Answer by Cap · Jun 03, 2010 at 11:37 AM

As long as the camera's target is a non static member variable (ie it's declared outside any functions, at the very top of the script file as just var target : GameObject; or similar) you can assign your car to that in the Start or Awake events. Just use GetComponent("CarCamera").target = whatever, or use GetComponentInChildren if you parent the camera to the car's master game object. So just move your target variable outside any functions (and you may want to move the camera variable out too). Declare them at the top of the file using var name : GameObject; and then populate them further down.

Bear in mind that you'll want to declare the camera's target variable in its own script file attached to your camera, not the car, so look there for it instead of in your own spawn file.

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

No one has followed this question yet.

Related Questions

2 players 1 game field in shooter/card game 0 Answers

Multiplayer click and spawn 1 Answer

How to make a gun look different to other cameras? 1 Answer

Have Camera Render First Person Arms But Not Body. 2 Answers

How to make camera position relative to a specific target. 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