So I made a script which syncs the position and rotation of a football and sends it to the clients of my game :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class playersyncposition : NetworkBehaviour {
[SyncVar]
private Vector3 syncPos;
[SerializeField] Transform mytransform;
[SerializeField] float lerprate = 15;
// Update is called once per frame
void FixedUpdate()
{
TransmitPosition();
LerpPosition();
}
void LerpPosition()
{
if (!isLocalPlayer)
{
mytransform.position = Vector3.Lerp(mytransform.position, syncPos, Time.deltaTime * lerprate);
}
}
[Command]
void CmdProvidePositionToServer(Vector3 pos)
{
syncPos = pos;
}
[ClientCallback]
void TransmitPosition ()
{
if (isLocalPlayer)
{
CmdProvidePositionToServer(mytransform.position);
}
}
}
But when I play the game the ball just glitches about. When I add a network transform, the host is able to interact with the ball perfectly but the client cannot do so. Please help me