Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by willoreagan · Nov 10, 2015 at 01:07 AM · networkingrespawning

I can't get player to respawn over network.

I am using a Unity Platforming Demo and can not get the player to respawn to the proper place over the network. The funny thing is, every once in a while, maybe 1/8, he'll respawn (which is just setting his position) works. For the most part, the player's position ends up being where he was last (which is falling offscreen)

I am using the a server-side kill trigger, and a ClientRPC to respawn. I am setting the position both in the server script and client script. I've tried many enumerations and combinations, even setting the transform of the rigid body or collision body transforms.

It seems that nothing gets this to work properly, and the player always ends up falling offscreen.

Here is my clientRPC for respawning.

 [ClientRpc]
     public void RpcRespawn (Vector3 pos)
     {
         Debug.Log("player respawned at position: " + pos.ToString());
         gun.enabled = true;
         playerControl.enabled = true;
 
         health = 50f;
         healthBar.enabled = true;
         UpdateHealthBar();
 
         gameObject.transform.position = pos;
         respawned = true;
     }
 
     [ClientRpc]
     public void RpcShutdown()
     {
         Debug.Log("player shutdown");
         gun.enabled = false;
         playerControl.enabled = false;

         healthBar.enabled = false;
     }


Also, here is my serve-rside code

  IEnumerator ReloadGame()
         {            
             // ... pause briefly
             while (timeToRespawn.Count > 0)
             {
                 yield return new WaitForFixedUpdate();
                 for(int i = 0; i < timeToRespawn.Count; i++)
                 {
                     timeToRespawn[i] -= Time.deltaTime;
                     if (timeToRespawn[i] < 0)
                     {
                         //MAKE RPC CALL HERE!
                         Debug.Log("Time to respawn count: " + timeToRespawn.Count.ToString() + " ip address: ");
                         GameObject player = objsToRespawn[i];
                         
                         
     
                     
                         startPosition = NetworkManager.singleton.GetStartPosition().transform.position;
                         player.GetComponent<PlayerHealth>().RpcRespawn(startPosition);
                         player.transform.position = startPosition;
                         timeToRespawn.RemoveAt(i);
                         objsToRespawn.RemoveAt(i);
                         //Debug.Log("Player Respawned" + player.name + "at position: " + startPosition.ToString());
                         break;
                     }
                 }
     
     
             }
         }

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
0

Answer by Slences · Nov 10, 2015 at 08:16 PM

I'm not sure why you call

 player.transform.position = startPosition;

after

 player.GetComponent<PlayerHealth>().RpcRespawn(startPosition);
                      

since you're setting the Gameobjects' position in the RpcRespawn method.

I'm not sure how to fix your problem, but maybe showing you my working respawn script will help you out:

  // Called on server
  foreach (GameObject player in getPlayerGameObjects())
  {
      PlayerStats pStats = player.GetComponent<PlayerStats>();
      PlayerState pState = player.GetComponent<PlayerState>();
      // Some stat resets that need to happen on server to the client
      pStats.isDead = false;
      pStats.health = pStats.maxHealth;
      // Client side stuff that needs to be called for respawning
      pState.RpcPlayerHandleSpawn();

      // And finally set the players' position
      SpawnPlayerToPosition(player, spawnPoints[i].transform.position);
   }

 [Server]
 void SpawnPlayerToPosition(GameObject player, Vector3 pos)
 {
     player.GetComponent<PlayerState>().RpcSetPlayerPosition(pos);
 }

 [ClientRpc]
 public void RpcSetPlayerPosition(Vector3 pos)
 {
     ctm.targetPosition = pos;
     transform.position = pos;
 }

 [ClientRpc]
 public void RpcPlayerHandleSpawn()
 {
     if (!isLocalPlayer)
          return;

     // Other client side stuff etc...
     GetComponent<CapsuleCollider>().enabled = true;
     GetComponent<CharacterController>().enabled = true;
    
 }

Hope that helps!

Comment
Add comment · 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

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

41 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiplayer Unet spawn on second player connect. 0 Answers

How can I read In a twitter # 1 Answer

Designing a multiplayer lobby for LAN 1 Answer

Unet - whats the best approach for a global game manager? 0 Answers

Bypassing network match password 0 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