Player Teleport Not Syncing Across the Network Properly
Hi. I am making a game where I want players to be able to teleport to any position on the terrain that they can look at. I am doing it by having them produce a projectile which moves very quickly, and, when it collides with the terrain, it teleports them where the collision happened. This works perfectly fine in In single player. In multiplayer: the host can successfully teleport, however, if the client tries to teleport, he only teleports on the hosts version of the game. Once this happens, if the client moves/camera changes, the host then gains the clients version of the game.
What I would like is for the client players to teleport on all version of the game (perhaps especially its own).
I am pretty much new to networking and am finding the documentation largely unhelpful.
This is the code I was trying to use for this;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityStandardAssets.Characters.FirstPerson;
public class blinkscript: NetworkBehaviour {
void OnCollisionEnter(Collision col)
{
RpcDoStuff ();
}
[ClientRpc]
void RpcDoStuff(){
var location = gameObject.GetComponent<Rigidbody> ().position;
var caster = gameObject.name[gameObject.name.Length -1];
Destroy (gameObject);
var player = GameObject.Find ("player" + caster);
player.GetComponent<Transform> ().position = location;
}
}
This script is attached to the spawned instance of the thing that collides with the terrain. Any Suggestions Would Be Appreciated.