The following code is crouching for a first person camera. When the player presses left CTRL, the camera moves down on its Y-axis to the crouch height, then if the player presses it again, it will return the height to the original Y Value. How can I make it so that the transition between the two values is smooth?
void checkCrouch()
{
originalHeight = crouchDepth * -1f;
if (isCrouched == true)
{
Debug.Log("nowcrouching");
Vector3 newPosition = transform.position; // We store the current position
newPosition.y += crouchDepth; // We set a axis, in this case the y axis
transform.position = newPosition;
}
else
{
Debug.Log("nolongercrouching");
Vector3 newPosition = transform.position; // We store the current position
newPosition.y += originalHeight;// We set a axis, in this case the y axis
transform.position = newPosition;
}
}