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 *-= Time.deltaTime;*
_ if (timeToRespawn < 0)_
* {*
* //MAKE RPC CALL HERE!*
* Debug.Log("Time to respawn count: " + timeToRespawn.Count.ToString() + " ip address: ");*
_ GameObject player = objsToRespawn*;*_
* startPosition = NetworkManager.singleton.GetStartPosition().transform.position;*
* player.GetComponent().RpcRespawn(startPosition);*
* player.transform.position = startPosition;*
* timeToRespawn.RemoveAt(i);*
* objsToRespawn.RemoveAt(i);*
* //Debug.Log(“Player Respawned” + player.name + "at position: " + startPosition.ToString());*
* break;*
* }*
* }*
* }*
* }*