Why this code for my camera is not smooth?
So, i've been working on my camera system. It was complex and useful, but it had some shakiness that I didn't like at all.
To solve my problem I started reducing the code, and well, I ended up with this very short lines of code.
They are very simple, the object moves with some Lerp inside the fixed update, they are physics so they need to be inside fixed update, and the camera smoothly follows that object, doing it inside LastUpdate because that's how it should be, technically.
I don't know what i'm doing wrong. I can't move my code from the object from fixed update to another place because my full game would be destroyed.
Any Idea? code for the object moving:
public float velocity;
public float time = 0.1f;
Vector3 pos;
private void FixedUpdate()
{
pos += Vector3.forward * velocity;
transform.position = Vector3.Lerp(transform.position, pos, time);
}
code for the camera:
public GameObject player;
public float time = 0.1f;
private void LateUpdate()
{
transform.position = Vector3.Slerp(transform.position, player.transform.position + Vector3.forward * -5, time);
}
Your answer
Follow this Question
Related Questions
C# Smooth Follow Space Ship 1 Answer
Create a smooth camera without jittering/flickering in 2D 3 Answers
Another Smooth Camera Follow problem 1 Answer
Cinematic feel for 3D First Person Camera 0 Answers
2D Sample Camera Script malfunctioning 0 Answers