It's possible your Update() loop is causing an FPS decrease. I believe Physics.Raycast expense increases with distance, and NavMeshAgent.SetDestination is rather expensive as well (it's been a while since I benchmarked it though). I made some optimizations here (won't fix the jittery movement though, more on that later):
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
// 500f might still be too much, adjust as needed
if (Physics.Raycast(ray, out hit, 500f)
{
float distance = nav.destination.DistanceTo(hit.point, true);
// adjust the 1f as needed
if (distance > 1f)
{
if (!nav.SetDestination(hit.point))
{
Debug.LogWarning("Could not find valid path to target");
return;
}
}
}
}
}
You'll need this extension method:
public static class ExtensionMethods
{
// credit: Unity Engine
public static float DistanceTo(this Vector3 a, Vector3 b, bool ignoreHeight = false)
{
Vector3 vec3
= new Vector3
(a
.x - b
.x, a
.y - b
.y, a
.z - b
.z); if (ignoreHeight)
vec3.y = 0f;
return Mathf.Sqrt((float)((double)vec3.x * (double)vec3.x + (double)vec3.y * (double)vec3.y + (double)vec3.z * (double)vec3.z));
}
}
Making networked movement appear smooth is quite difficult and depends a lot on your specific needs. The AutoSync script is included more as an example than a final solution. It's always been recommended that you write your own movement code. Here are the two major approaches:
1. Sync input
* In your case, you could sync every button click (with rate limiting to avoid those ultra-fast clickers

2. Sync the transform (this is what the AutoSync script does, but in the least efficient way

)
* Deltas (sync only what has changed and the amount it changed)
* Float compression (this comes with a loss of precision, but in most cases not significant. 4 bytes reduced to 1 byte)
In both cases you'll have to deal with ping (this is what causes the jittery appearance). Easiest way to solve this is interpolating between movement updates. Aren has explained this really well, so I'll just paste those links here:
http://www.tasharen.com/forum/index.php?topic=6538.msg33291#msg33291The LagPosition script (that performs the interpolation) can be found here:
http://www.tasharen.com/forum/index.php?topic=11830.msg54898#msg54898In short you'll want to split your networked objects into two parts: the "real" transform, and the "display" transform. From a user perspective, you'll be seeing the "display" transform. The "display" transform is constantly chasing after the "real" transform via linear interpolation. The "real" transform is what receives and processes the movement update.