Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by KingKongFu · Jan 17, 2013 at 07:23 PM · networkingspawnpoints

Player Spawn point not changing

Hey everyone. I am getting my feet wet in networking now and I cannot get different spawn points for when a player joins the game it keeps going back to the same spawn point. My player count variable does not change or it somehow gets reset in the code or something to it wont increment.

Here is what I got it work but does not change spawn points. Thanks for any help with this.

 var remoteIP = ""; //ip of comp tring to connect to
 var remotePort = 25000;
 var listenPort = 25000;
 var useNAT = false;
 var yourIP = ""; //server address
 var yourPort = ""; // port
 
 var playerCount : int;
 public var spawnPoints : Transform[];
 
 //player and jump master spawn componets
 var playerPrefab : GameObject;
 //spawn points
 var sp1: Transform;
 var sp2: Transform;
 
 //camera stuff
 private var cam : Camera;
 public var skyBoxMat : Material;
 
 var camHarness : GameObject;
 
 
 function Start () {
     playerCount = 0;
 
 }
 
 
 function OnGUI()
 {
     if(Network.peerType == NetworkPeerType.Disconnected)
     {
         //connect to server
         if(GUI.Button(Rect(10, 10, 100, 30), "Connect"))
         {
             Network.useNat = useNAT;
             Network.Connect(remoteIP, remotePort);
         }
         //creat own server
         if(GUI.Button(Rect(10, 50, 100, 30), "Start Server" ))
         {
             Network.useNat = useNAT;
             //first number is max connections
             Network.InitializeServer(14,listenPort );
             
             //loop though every object in the game
             for(var go : GameObject in FindObjectsOfType(GameObject))
             {
                 go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
             }
         }
         //use these for accsessing the server that not hard coded
         remoteIP = GUI.TextField(Rect(120, 10, 100, 20), remoteIP);
         remotePort = parseInt(GUI.TextField(Rect(230, 10, 40, 20), remotePort.ToString()));
     }else
     {
         //if player is connected to the game
         var ipAddress = Network.player.ipAddress;
         var port = Network.player.port.ToString();
         //see ip and port for connected player
         GUI.Label(Rect(140, 20, 250, 40), "IP Address: " + ipAddress + " port : " + port);
         
         if(GUI.Button(Rect(10,10,100, 50), "Disconnect"))
         {
             Network.Disconnect(200);
         }
     }
 }
 
 //spwan the master jumper
 function OnServerInitialized()
 {
     Debug.Log("Server initilized");
     spawnPlayer();
     playerCount++;
 
     
 }
 
 function OnConnectedToServer()
 {
     //loop though every object in the game
         for(var go : GameObject in FindObjectsOfType(GameObject))
         {
             go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
         }
         
         spawnPlayer();
         playerCount++;
 
 }
 
 
 
 //spawn player prefab
 function spawnPlayer()
 {
     //Network.Instantiate(playerPrefab, sp1.position, Quaternion.identity, 0);
     
     Debug.Log("Player Count" + playerCount);
     if(playerCount == 0)
     {
         Network.Instantiate(playerPrefab, sp1.position, Quaternion.identity, 0);
     } 
     if(playerCount == 1)
     {
         Network.Instantiate(playerPrefab, sp2.position, Quaternion.identity, 0);
     }
     //Network.Instantiate(playerPrefab, sp1.position, Quaternion.identity, 0);
     //Network.Instantiate(playerPrefab, spawnPoints[playerCount].position, Quaternion.identity, 0);
     playerCount++;
     camHarness = GameObject.Find("CamHarness");
     cam = gameObject.AddComponent(Camera);
     var rot : Quaternion;
     rot.x = camHarness.transform.rotation.x;
     rot.y = camHarness.transform.rotation.y;
     rot.z = camHarness.transform.rotation.z;
     rot.w = camHarness.transform.rotation.w;
 
     cam.transform.position = camHarness.transform.position;
     cam.transform.rotation = rot;
     cam.transform.parent = camHarness.transform;
     //set near and far view for camera
     cam.near = 0.1f;
     cam.far = 35000;
     
     RenderSettings.skybox = skyBoxMat;
     
 
     
 }
 
 
 
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by danilonishimura · Jan 17, 2013 at 10:23 PM

When you connect to a server, you need to spawn the other players before spawning you, otherwise, when you enter the room, you'll always be the first, and therefore, always spawn in the zero position.

Updated:

Reading more carefully, I saw that you're not listening to the OnPlayerConnected event.

Here is the method you should implement on your code:

 function OnPlayerConnected(networkPlayer:NetworkPlayer):void
 {
     Debug.Log (networkPlayer.guid + " connected");
     spawnPlayer();
 }


Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KingKongFu · Jan 17, 2013 at 10:49 PM 0
Share

That make sense to me but I fail to see how to do that

avatar image KingKongFu · Jan 23, 2013 at 06:22 PM 0
Share

Thank you I think I got it working. well the player count is going up so now I just have to edit where they spawn. Thanks again!

avatar image ajaybhojani · Jan 01, 2016 at 06:06 AM 0
Share

hi.. getting same problem... I have spawned player successfully :) But trying to display own player on screen centre position and other joined player should be available either left or right. Each player can see his position on center in his app. Is it possible ? I am using photonview.is$$anonymous$$e method. But not succeed.

please help

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NetworkSpawnpoint not working 0 Answers

Having trouble randomizing spawns on Tanks! Networked from asset store 0 Answers

Unity networking tutorial? 6 Answers

Network Transform Component forcing Object to a specific position + rotation 0 Answers

[UNET] Dynamically position NetworkStartPosition Gameobjects 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges