I am trying to use lerp on a camera position to seek it’s target but with no great result, it isn’t fluid when seeking fast, slow lerp is ok tho. it’s as if I was using Update() rather than LateUpdate or something like that:
I am currently doing the race tut ( to give you an idea of the environment I am in. and this is a simple alteration of the /1 Basic Follow Camera/camera.js
Here is the code.
var target : Transform;
var distance = 10.0;
var height = 5.0;
function LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// Get the forward direction of the target
forward = target.TransformDirection (Vector3.forward);
newPosition = target.position - forward * distance + Vector3(0,height,0);
transform.position = Vector3.Lerp(transform.position, newPosition, 0.8*Time.deltaTime);
// Always look at the target
transform.LookAt (target);
}
damping with 0.8 increase the fluidity but higher value increases the unwanted effect…
If I understand what you are doing correctly then there is just one small mistake in your code. Instead of transform.position = Vector3.Lerp(transform.position, newPosition, 0.8*Time.deltaTime);
…you probably wanttransform.Translate((newPosition - transform.position) * (0.8 * Time.deltaTime), Space.World);
(That is to say, you don’t need the Lerp in this particular case.)
You might need to change the constant 0.8 to something smaller or larger (but still between 0 and 1) to get the right camera speed, however. A useful trick is to make this a public variable and change its value while the game is running. Try different values until you get it just right and then make a note of the final value before you stop the running game.
Thanks. It does produce the same unwanted artifact so I assume that my issue is actually not the camera behavior but the actual target that is the cause of this shaking. I will investigate.
is your camera shaking too?? cause i have the same effect on the camera and don’t know why! in the first i feel that the target that shaking but the target dosen’t rotate at all, why is that happened? did u figure out this problem?
i use the Lerp function also on my camera script.