- Home /
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++;
}
how do i get the green tank to face the other way?
What do you try to achieve with the line
Instantiate = new Vector3(-1,0,0);
The problem must be at line 15, when you instantiate the second player (the client), you instantiate it with Quaternion.identity, but you don't want that. This is what controls the rotation.
Yes, but what you need to do is create a Spawnpoint1 with the position you already have AND a good rotation, same for Spawnpoint2 but with an opposite rotation.
Then you do :
if (Network.peerType == NetworkPeerType.Server)
{
playerObj = (GameObject)Network.Instantiate(playerPrefab, SpawnPoint1.transform.position, SpawnPoint1.transform.rotation, 0);
nView = (NetworkView)playerObj.GetComponent("NetworkView");
Debug.Log("Spawned Player 1");
}
else
{
playerObj = (GameObject)Network.Instantiate(playerPrefab2, SpawnPoint2.transform.position, SpawnPoint2.transform.rotation, 1);
nView = (NetworkView)playerObj.GetComponent("NetworkView");
Debug.Log("Spawned Player 2");
}
when I do it that way, I get an error saying left hand side of an assignment must be a variable, a property or indexer
Answer by KiraSensei · Apr 25, 2014 at 10:00 PM
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
Answer by Mint92 · Apr 25, 2014 at 11:09 PM
"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"
Your answer
![](https://koobas.hobune.stream/wayback/20220613143454im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Position an instantiated prefab relative to its translation vector 2 Answers
Unet NetworkServer.Spawn() not working 5 Answers
Different between transform.Translate() and Vector3.MoveTowards? 1 Answer
My energy bar decrease only on the host screen with network 0 Answers
Network.Instantiate Problem 1 Answer