Network.Instantiate Spanws player 2 wrong way

public void spawnPlayer()
{
GameObject playerObj = null;
NetworkView nView = null;

		// note: Network.Instantiate is a buffered call
		 if (Network.peerType == NetworkPeerType.Server)
		{
			playerObj = (GameObject)Network.Instantiate(playerPrefab, SpawnPoint1.transform.position, Quaternion.identity, 0);		
			nView = (NetworkView)playerObj.GetComponent("NetworkView");
			Debug.Log("Spawned Player 1");
		}
		else
		{
			playerObj = (GameObject)Network.Instantiate(playerPrefab2, SpawnPoint2.transform.position, Quaternion.identity, 1);	
			Instantiate = new Vector3(-1,0,0);
			nView = (NetworkView)playerObj.GetComponent("NetworkView");
			Debug.Log("Spawned Player 2");			
		}
		
		if (Network.peerType == NetworkPeerType.Server)
		{
			Debug.Log("Server spawning player" + Network.player);
		}
		else
		{
			networkView.RPC("Log", RPCMode.Server, "Client spawning player" + Network.player);
		}
		
		nView.RPC("SetOwner", RPCMode.AllBuffered, Network.player);
		
		playerID++;
		playerCount++;		
	}	

25687-tank2.jpg

how do i get the green tank to face the other way?

So, good new, everything is working now !

There were several problems:

  • you were checking transform.rotation values, but since you rotated the whole prefab, the z value of the turret was stupid (like 10^-8 everytime), so now I changed it to transform.localRotation, that checks only the turret rotation.

  • your player 2 prefab had a problem, there was a different game object attached to it (I can’t understand what it was), so I deleted the player 2 and recreated from player1 correctly. By the way, since, player1 and player2 have the same prefab, except for the color, I would suggest you to keep only one prefab with the red material for example, and change the materials for the second one. That way your game will be lighter.

  • You use several obsolete functions (the warnings are poping up a lot in the log window), I would suggest you to use the new functions to avoid future problems.

Here is the link : PROJECT

"So, good new, everything is working now !

There were several problems:

you were checking transform.rotation values, but since you rotated the whole prefab, the z value of the turret was stupid (like 10^-8 everytime), so now I changed it to transform.localRotation, that checks only the turret rotation.

your player 2 prefab had a problem, there was a different game object attached to it (I can’t understand what it was), so I deleted the player 2 and recreated from player1 correctly. By the way, since, player1 and player2 have the same prefab, except for the color, I would suggest you to keep only one prefab with the red material for example, and change the materials for the second one. That way your game will be lighter.

You use several obsolete functions (the warnings are poping up a lot in the log window), I would suggest you to use the new functions to avoid future problems"