- Home /
Copy position Smoothing
Hello,
I have been at this issue for a couple of days now and its time I ask the great community. I am making a flying game with a third person follow camera. I have an camera parented to an empty which is copying the rotation of the plane. In order to actuallly follow the plane I then have it so the empty copies the position of the plane as the empty is on the planes pivot point.
It was a very jerky follow camera so naturally I added some smoothing like so:
MainCamera.position = Vector3.Slerp(MainCamera.position,transform.position, Time.deltaTime * SmoothTime);
This works fine but my issue is the camera is falling behind, and the faster the plane travels the more the camera falls behind. Turning the "SmoothTime" down has no effect and turning it up works until a certain value (45 atm). After the value is reached it becomes jerky again.
How can I stop the camera from falling behind while still retaining the smoothing?
Answer by Wolfram · Jun 18, 2012 at 09:49 AM
Put your code in LateUpdate(), to prevent execution order conflicts - all scene transformations should happen first, and at the last possible moment adapt your camera position to the current situation.
Thanks I fixed it by changing the way the planes moves from Translate to ConstantForce. This seemed to work but Thank you for your help!
Answer by asafsitner · Jun 17, 2012 at 07:48 PM
I think you want to use Lerp
as in Linear Interpolation and not Slerp
as in Spherical Linear Interpolation. The latter is used for rotation smoothing, not position.
You can use Vector3.Distance to determine when the camera is falling behind too much and accelerate/decelerate it accordingly, or make SmoothTime relative to the plane's speed.
Thanks for your help, I have tried making SmoothTime relative to the planes speed, but as I said when smoothtime gets to high it jitters again