- Home /
Using Different Cameras in Network.
Hi all,
I have a question using the Network and the cameras. I have a server and different clients can connect, they should have their own First Person Camera, so in the prefab i instantiate I have added a camera also i have a Main Camera for the server.
The problem is: when Client1 connects, he uses his own camera, and the server too. But when the Client2 connect, Server, Client1 and Client2 use the Client2 camera. And always like this. All the "players" uses the camera from the last client connected. I have looked information about this, but i cant find anything.
Thank you in advance.
You should be able to say 'new camera pCam' in the camera file. Then ins$$anonymous$$d of using the default camera as the scripted camera reference, you use the pCam so the engine knows your using the player specific camera
Answer by Pangamini · Jan 14, 2014 at 06:51 PM
Let's say there's a world, it's populated by characters (and crates, bombs, monsters, rum whatever). Players connect to the server and each player controls one character. But the observer is the player, not the player's controlled character. Simply: there should only be one camera and it should not be part of the character.
What happens in your scenario is that each character spawns with a camera. When there's 2 or more, they simply draw over each other and you only see the last one. But no player is going to use other player's camera, they shouldn't even exist on their pc. So what you should do is:
Have a controller object, which is one in the scene. This controller will be set to control one of the characters (most likely the one the local player owns). It will read the local player's input (that's right, there is no Input.GetAnything in the character's code) and send commands to the controlled character. It will also read the character's state and move the camera to adequate position (dunno if you are doing first or third person, so this is up to you).
No matter what happens, there will not be multiple controllers in the scene at the same time.
Networking of a game is quite hard and tricky, you need to learn distinguish what's clientside (controller) and serverside (characters)
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
How to apply target, while created at runtime? 1 Answer
camera only sticks to the master client 0 Answers
Follow camera jitters on multiplayer clients 1 Answer
How do I make a camera look for a specific GameObject while networking? 1 Answer