Hello, I am working on my first 2D game in Unity. And I have some struggles with camera, which seems lagy. It is like micro lags, when camera is folowing the players, sometimes. Should it be, because I used it in Update method?
My code looks like this:
void Update()
{
playerPosition = new Vector3(player.transform.position.x, player.transform.position.y, transform.position.z);
if (player.transform.localScale.x > 0f)
{
playerPosition = new Vector3(playerPosition.x + offset, playerPosition.y, playerPosition.z);
}
else
{
playerPosition = new Vector3(playerPosition.x - offset, playerPosition.y, playerPosition.z);
}
transform.position = Vector3.Lerp(transform.position, playerPosition, offsetSmoothing * Time.deltaTime);
}
What I have tried:
My thoughts are. That update method will make some actions every next frame. So if it is 110 fps, camera moved 110 times. Should I make it on lower fps, or put the code somewhere else, just not in Update method? Thank you.