Garbage collection events

I am lerping my camera movement like so.

        head.transform.localPosition = new Vector3(0f, 0.45f, 0f);

        mouseX = Input.GetAxisRaw("Mouse X") * data.sensitivity * Time.deltaTime;
        mouseY = Input.GetAxisRaw("Mouse Y") * data.sensitivity * Time.deltaTime;

        xSmoother = Mathf.Lerp(xSmoother, mouseX, data.smoothness * Time.deltaTime);
        ySmoother = Mathf.Lerp(ySmoother, mouseY, data.smoothness * Time.deltaTime);
        yRotation += xSmoother;
        xRotation -= ySmoother;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        head.transform.rotation = Quaternion.Euler(xRotation, yRotation, 0f);

To create smoother camera movement but whenever the GC hits it will “spasm” and the camera rotation will wind up way off course.

It doesn’t look like the GC has any OnBefore/OnAfter events where I can turn the smoothing off? Unity - Scripting API: GarbageCollector

Remove the Time.deltaTime from lines 3 and 4. The mouse delta is frame rate independent and so multiplying it by Time.deltaTime makes it frame rate dependent.

1 Like

That works thanks zulo.

… you would normally use Cinemachine! :wink:

We don’t script the camera anymore … or if we do, we script the Cinemachine components.