in my scene i have an object that is projected onto the nearest surface behind the cursor with this script:
using UnityEngine;
using System.Collections;
public class CursorHit : MonoBehaviour {
public HeadLookController headLook;
// Update is called once per frame
void LateUpdate () {
Ray cursorRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(cursorRay, out hit)) {
transform.position = hit.point;
}
headLook.target = transform.position;
}
}
this is currently the script i am using to make the camera follow the player character when it moves:
using UnityEngine;
using System.Collections;
public class SmoothFollowCamera : MonoBehaviour {
public GameObject target;
public float smoothingTime = 0.5f;
public Vector3 offset = Vector3.zero;
public float rotateAngle = 45;
public float rotateTime = 25;
public bool useBounds = false;
private SmoothFollower follower;
// Use this for initialization
void Start () {
follower = new SmoothFollower(smoothingTime);
}
// Update is called once per frame
void LateUpdate () {
if (target==null) return;
Vector3 targetPoint = target.transform.position;
if (useBounds) {
Renderer r = target.GetComponentInChildren(typeof(Renderer)) as Renderer;
Vector3 targetPointCenter = r.bounds.center;
if (!float.IsNaN(targetPointCenter.x)
&targetPointCenter.magnitude < 10000) targetPoint = targetPointCenter;
}
transform.position = follower.Update(targetPoint + offset, Time.deltaTime);
transform.rotation = Quaternion.AngleAxis(
Mathf.Sin(Time.time*2*Mathf.PI/rotateTime)*rotateAngle,
Vector3.up
);
}
}
it may also be worth noting that the player character faces the cursor object based on the Head Look Controller.
whenever the camera moves, the object that follows the cursor jitters. changing the scripts to use different combinations of Update and LateUpdate did not yield a satisfying, predictable solution (and as i understand it, the camera should always use LateUpdate.) what should i change to ensure smooth movement of both the cursor-following object and the camera itself?