Over my unet network I have attached a network transform and identity to my player object which the server spawns. When it moves, all clients and the host can see it move.
The players then spawn a child object which also has an identity and network transform, the client can see the hosts childs moves, but the host cannot see the other clients childs moves.
Any help, thanks!!
Maybe you can start with this:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Object_SyncPosition : NetworkBehaviour {
private Transform myTransform;
[SerializeField] float lerpRate = 5;
[SyncVar] private Vector3 syncPos;
// private NetworkIdentity theNetID;
private Vector3 lastPos;
private float threshold = 0.5f;
void Start () {
myTransform = GetComponent<Transform> ();
syncPos = GetComponent<Transform>().position;
}
void FixedUpdate () {
TransmitPosition ();
LerpPosition ();
}
void LerpPosition () {
if (!hasAuthority) {
myTransform.position = Vector3.Lerp (myTransform.position, syncPos, Time.deltaTime * lerpRate);
}
}
[Command]
void Cmd_ProvidePositionToServer (Vector3 pos) {
syncPos = pos;
}
[ClientCallback]
void TransmitPosition () {
if (hasAuthority && Vector3.Distance(myTransform.position, lastPos) > threshold) {
Cmd_ProvidePositionToServer (myTransform.position);
lastPos = myTransform.position;
}
}
}
2 Likes
I had to move the Command function to the parent player object as the child didn’t have client authority even though I spawned it with it. But it works, thanks you very much!
u welcome