I'm working on a project with an indie studio and I was asked to make a change to the way the camera works so when the player is looking up, the camera zoom in, and when the player is looking down the camera zoom out.
My solution works, but it's too snappy. The camera will zoom but in an instant. I've tried adding more larping or smoothing but it didn't helped. I'm sure there's more elegant way to do it. Glad if anyone can help.
float currentPitch = Values.pitch;
if(currentPitch > lastFramPitch){
Values.runTimeDistanceFromTarget.z += Values.zoomSensitivity;
Values.runTimeDistanceFromTarget.z = Mathf.Lerp(Values.runTimeDistanceFromTarget.z , Values.zoomIn , Values.zoomSensitivity);
}
else{
Values.runTimeDistanceFromTarget.z -= Values.zoomSensitivity;
Values.runTimeDistanceFromTarget.z = Mathf.Lerp(Values.runTimeDistanceFromTarget.z , Values.zoomOut , Values.zoomSensitivity);
}
lastFramPitch = currentPitch ;
Cinemachine does this out of the box with easy parameters to adjust. It also lets you transition between any camera at any time.