Multiplayer Camera Issues

I put this over on multiplayer networking, but I thought I’d put it here just in case as well. So basically, I’m attempting to make a small multiplayer game. Now, I’ve created my camera and am using a script to tell it who controls it, but either as the server or client, it connects to the same camera, and the players cannot use it. Not sure why it’s working like this, because I should have all the logic intact. Here’s the code, let me know what you think.

 //This script sets up the camera and will apply it's movement when the player moves it. 

var speed = 6.0; //speed at which the camera moves per frame. 
var startheight = 10.0; //the height at which the camera is first placed. 
var startrotation = 90.0; //the rotation of the camera, currently 90 in order to create a top-down game. 
var scrollspeed = 6.0;//the speed of the scrollwheel to zoom in and out. 
var target : Transform; //grabs the target of the camera, in this case, the player's avatar. 

private var moveDirection = Vector3.zero; //setting up the position vector. 

function Awake() //when the object is created on the network 
{ 
   if (!networkView.isMine) //if the object is not on the user's network 
   { 
      enabled=false; //disable the object. 
   } 
} 

function Start() //at the start of the game 
{ 
   transform.Rotate (startrotation, 0, 0, Space.World); //setting initial rotation of camera. 
   Reset(); //calls reset function to situate the player above their avatar. 
} 

function Reset() 
{ 
   if (Network.peerType == NetworkPeerType.Server) 
   { 
      transform.Translate (0, startheight, 0, Space.World); 
   } 
   else 
   { 
      transform.position = Vector3(0,0,0); //sets the original position of the camera. 
      var plTransform = target.GetComponent(Transform); //gets the position of the camera and assigns it to variable 
      var plxPosition = plTransform.position.x; //gets the x value of the avatar's position. 
      var plzPosition = plTransform.position.z; //gets the z value of the avatar's position. 
      transform.Translate (plxPosition, startheight, plzPosition, Space.World); //actually moves the camera to the player's position, with distinction for height. 
   } 
} 

function Update() 
{ 
   if (networkView.isMine) 
   { 
      if (Input.GetAxis ("Horizontal") || (Input.GetAxis ("Vertical"))) //if the movement keys are being pressed... 
      { 
         var newx = Input.GetAxis("Horizontal") * speed; //gets the x change in the mouse position    
         var newz = Input.GetAxis("Vertical") * speed; //gets the y change in the mouse position, to be changed to z. 
         transform.Translate (newx, 0, newz, Space.World); //translates the object 
      } 
      else if (Input.GetAxis("Mouse ScrollWheel")) //if the mouse scrollwheel is being used... 
      { 
         var newy = (Input.GetAxis("Mouse ScrollWheel") * scrollspeed) * -1; //gets the value and assigns it to a variable. 
         transform.Translate (0, newy, 0, Space.World); //moves the camera up or down 
      } 
      else if (Input.GetButton ("ResetCamera")) //if the reset camera button is pressed... 
      { 
         Reset(); //reset the camera. 
      } 
      else //if nothing 
      { 
         return; //stops script 
      } 
   } 
   else 
   { 
      return; 
   } 
} 

function OnSerializeNetworkView(stream : BitStream, info : NetworkMessageInfo) 
{ 
   if (stream.isWriting) 
   { 
      var pos : Vector3 = transform.position; 
      stream.Serialize(pos); 
   } 
   else 
   { 
      var posReceive : Vector3 = Vector3.zero; 
      stream.Serialize(posReceive); 
      transform.position = posReceive; 
   } 
}

[/code]

i have a problem too, if there are 2 cameras on multiplayer(2 players with theyre own camera) the monitor jumps from camera 1 to camera 2 every part of a second, i cant figure how to fix it. any ideas?

I had the same issue two days ago. I fixed it, but I’m not sure how. My topic became pretty large. Though you might wanna check it out and see if there’s something useful for you.

My first question is not about cameras, but then I get the problem.
http://forum.unity3d.com/threads/67158-Network-spawning-question

:slight_smile:

woaw! i have the same problem! :S