I'm trying to make it so that when my player velocity increases, the virtual follow cam orthographic size increases and when the player velocity decreases, the orthographic size decreases. When I try this though, it doesn't scale smoothly, it judders really badly.
My code looks something like this...
void Update()
{
// Take the fastest velocity (x or y)
if((Mathf.Abs(rb.velocity.x) > Mathf.Abs(rb.velocity.y))
{
velocity = Mathf.Abs(rb.velocity.x)
}
else
{
velocity = Mathf.Abs(rb.velocity.y)
}
//Set orthogrpahic camera size
if(velocity > 0)
{
vCam.m_Lens.OrthographicSize = Mathf.Clamp(defaultCamSize + velocity, defaultCamSize, maxCamSize);
}
else
{
vCam.m_Lens.OrthographicSize = defaultCamSize;
}
}
You could use
Mathf.Lerp()
, documentation says thatYou can write somthing like following to smoothly change the
orthographicSize