So, I have a client and server with an object that shares a networkview.
The server shows a first person view from the object, and the client has a camera with 2 different camera modes (but, that’s not important).
The server is fine, but the client camera shakes. Here is my code (I hacked it together from 2 scripts from Unifycommunity SmoothFollow2 and SmoothLookFrame):
using UnityEngine;
using System.Collections;
public class StationCamera : MonoBehaviour {
public bool boolean = true;
// Smooth Follow Variables
public Transform target;
public float distance = 3.0f;
public float height = 3.0f;
public float damping = 5.0f;
public bool smoothRotation = true;
public bool followBehind = true;
public float rotationDamping = 10.0f;
// Smooth Look Frame Variables
public Transform lookAtTarget;
public Transform frameTarget;
//public float distance = 10.0f;
//public float height = 5.0f;
//public float damping = 2.0f;
private Vector3 direction;
private Vector3 wantedPosition;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (boolean) {
// Smooth Follow Code
if(followBehind)
wantedPosition = target.TransformPoint(0, height, -distance);
else
wantedPosition = target.TransformPoint(0, height, distance);
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
if (smoothRotation) {
Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
}
else
transform.LookAt (target, target.up);
}
else {
if (!lookAtTarget || !frameTarget)
return;
direction = (frameTarget.position - lookAtTarget.position);
wantedPosition = frameTarget.position + (direction.normalized * distance);
wantedPosition.y = wantedPosition.y + height;
transform.position = Vector3.Lerp(transform.position, wantedPosition, damping * Time.deltaTime);
Quaternion rotate = Quaternion.LookRotation(lookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damping);
}
}
}
The only thing that works is turning the damping and rotationDamping variables up to about 500, but then I lose the smoothing effect when I change camera modes. Any help would be appreciated, I’ve tried changing the the state synchronization type, and changing Update to LateUpdate to no avail.