- Home /
Camera jitter when using Lerp/Slerp
I know similar questions have been asked already but I've been through almost all of them and none of the solutions seem to work for me. Basically I have a camera that pans to a predefined location when the mouse button is clicked, which works fine minus the somewhat subtle jitter.
static var cameraPosition : int;
function Update () {
if (cameraPosition == 1) {
transform.position = Vector3.Slerp (transform.position, target.transform.position, Time.deltaTime);
transform.rotation = Quaternion.Slerp (transform.rotation, target.transform.rotation, Time.deltaTime);
}
}
I've tried used function FixedUpdate and replacing Time.deltaTime with 1 - Mathf.Exp(-k * Time.deltaTime) but to no avail. The jitter exists for both the rotation and position. Any ideas?
I tried that too. Giving it a value such as 0.05 still results in jitter.
That's because even with a constant you are still constantly moving, even if just a tiny bit because in your system (that you've shown anyway) you never seem to accept the fact that you have arrived and cease Slerping.
Sorry for not specifying earlier. The jitter is at its worst during the peak speed of the camera pan, namely when it's about halfway to the target location. Just in case though, I tried your idea and stopped the camera from Slerping once it's distance to the target was less than 0.01
Oh wow. I tried it with the distance value of 0.1 and the camera Slerps so smoothly now. Don't really understand how that works but I'm glad it works nonetheless. Thanks a bunch.
Actually...I take that back. It seems to work more smoothly but there is still a noticeable jitter.
Answer by AchillesWF · Apr 22, 2012 at 02:11 AM
I think the jitter comes from the fact that you are always sending it essentially random (based on frame time) values to the Slerp() functions, which expect between 0 - 1 indicating the proper interpolation between the 2 extremes, not a time value.
Your answer
Follow this Question
Related Questions
Camera Lerp Jitter 0 Answers
3D menu camera rotation issue. 0 Answers
Lerping orthographic camera size jitters 1 Answer
Transition current camera rotation to 0,0,0 1 Answer
Movement Smoothing Script not Working 2 Answers