I rotate my camera using a framerate-independent exponential ease-out blend like so:
_x += Input.GetAxis("Mouse X") * xSpeed;
float target = 0f; //I want to blend towards 0
float sharpness = 0.05f; //the smaller this value, the longer it takes to settle down to the target value
float referenceFramerate = 90f;//the approximate framerate on my developer machine
float blend = 1f - Mathf.Pow(1f - sharpness, Time.deltaTime * referenceFramerate);
_x = Mathf.Lerp(_x, target, blend);
This works fine.
Now my camera should be clipped at a certain rotation yaw.
The new camera rotation yaw is calculated like this:
_CurrentYaw += _x * Mathf.Abs(_CameraDefaultPos.z);
if (_CurrentYaw > 160f)
{
_CurrentYaw = 160f;
}
else if (_CurrentYaw < -120f)
{
_CurrentYaw = -120f;
}
This clipping part of my code makes the camera stop abruptly at the maximum.
How could the above Mathf.Lerp function be adopted to make it so that the _x value would be damped more quickly when going towards the rotation limit?
_x
variable represents. It looked like it was a rotation angle, but in your latest edits we see it added to a_CurrentYaw
value - is that happening every frame, making_x
a rate of change over time? Should that not be delta-time-corrected too then? \$\endgroup\$_CurrentYaw
will change twice as fast, since you're adding_x
to it twice as often. \$\endgroup\$