- Home /
follow camera is jerky for other objects
I'm using the following code to have a camera follow an object. Whichever object the camera is looking at is followed smoothly, but other objects in the scene appear to have jerky movement. If I turn it off all objects move smoothly.
target is the gameObject I want to look at. offsetVector is Vector3(0,10,40); is to position the camera above and away from the target.
worldCameraObject.transform.position=Vector3.Lerp(worldCameraObject.transform.position,target.transform.position
+offsetVector,.5);
worldCameraObject.transform.LookAt(target.transform);
This is in the update loop.
What's offsetVector and have you tried any other value other than 0.5 for t?
Is your camera set as a child of a target?
Also, try to use Time.deltaTime in lerping ins$$anonymous$$d of that 0.5, that will help make camera movement framerate-independent.
I made up a simple scene with your code, but the movement is not jerky on my end. So my guess is, it is linked to something else in your scene... Is the animation jerky only if you move the target, or at all times?
Joyrider: Thanks for taking the time to try and verify it. I have three objects in my scene one object is forcing the other two to move to the right, the other two look jerky but the target object does not. Changing the lerp doesn't help.
Answer by renaissanceCoder1 · May 19, 2015 at 06:28 AM
This can happen if both your camera and object it is looking at are both updating in Update(). You will want your camera to update after the object is looking at is done making its movements. So put your camera update code in LateUpdate().
Your answer
Follow this Question
Related Questions
Camera follow smoothness problem 1 Answer
Smooth Follow Problem 1 Answer
Why does the camera smoothly follow in one direction but not the other? 0 Answers
[Closed] SmoothFollow trouble 0 Answers