In my Unity 2D platformer, I'm trying to move the camera down a bit when the character is crouching but not moving. I've done this with the following:
cameraPosition = mainCamera.transform.position.y; cameraPosition = Mathf.Lerp(cameraPosition, cameraPosition - 0.8f, 3 * Time.deltaTime); mainCamera.transform.position = new Vector3(mainCamera.transform.position.x, cameraPosition, mainCamera.transform.position.z);
This works, but it's causing the camera's y value to decrease continuously rather than just 0.8f, because
cameraPosition is assigned a new value every frame. But
cameraPosition has to be relative because its location depends on the player's location, so I can't figure out how else to write it.