- Home /
Networking Camera
Hey there! I've finally created a prototype of a MP Game - creating Server, joining and moving is no problem. But its actually not possible for me, to give every Player his own Camera. Just the Host gets a Camera, every else Player is only able to see the view through MainCam.
Script in NetworkSpawn
var Clone: Transform;
Clone = Network.Instantiate(playerPrefab, transform.position, transform.rotation,0);
Camera.main.SendMessage("SetTarget", Clone.transform);
and Camera Script:
var Target : Transform;
var distanceFromPlayer: int = 20;
function LateUpdate () {
if (Target)
{
transform.position.x = Target.position.x;
transform.position.z = Target.position.z - distanceFromPlayer;
transform.position.y = Target.position.y + distanceFromPlayer*1.5;
}
}
function SetTarget (t : Transform)
{
Target = t;
}
Any idea? Greets
Answer by syclamoth · Nov 27, 2011 at 01:23 AM
How about adding this one thing to your camera script? Just after it gets network instantiated.
if(!networkView.isMine)
{
camera.enabled = false;
}
Otherwise, make sure that the 'Main Camera' gets disabled on clients, or renders behind the other cameras (which isn't a fantastic way of blocking it, but will still work).
So I should not use the $$anonymous$$ainCamera, but a different Camera for Clients? Host can use $$anonymous$$ainCamera?
Well, you can use what you want- I usually just move the main camera around independently (as in, I don't synchronise it at all) so that all players just use that. Remember that if an object doesn't have a network view, it can be wherever it likes! However, in your question you said you were instantiating new cameras for every player- which is why I told you to disable the main camera (since the newly instantiated cameras on the players would interfere with it otherwise)
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Multiplayer camera switch issue 0 Answers
Assign spawned object to SmoothFollow target 1 Answer
Multiplayer Client Missing Reference To Spawn Object 1 Answer