I’m making a crouch mechanic for an fps game and mechanically it works well enough, but when I exit crouching the camera jitters a bit because the entire charactercontroller jitters. How can I make this smooth?
if (isCrouching)
{
characterController.height = Mathf.Lerp(characterController.height, 1.0f, Time.deltaTime * crouchTransitionDuration);
characterController.center = Vector3.Lerp(characterController.center, new Vector3(0, 0.5f, 0), Time.deltaTime * crouchTransitionDuration);
transform.position = new Vector3(transform.position.x, transform.position.y - 5f, transform.position.z);
}
else
{
characterController.height = Mathf.Lerp(characterController.height, 2.0f, Time.deltaTime * crouchTransitionDuration);
characterController.center = Vector3.Lerp(characterController.center, new Vector3(0, 0, 0), Time.deltaTime * crouchTransitionDuration);
transform.position = new Vector3(transform.position.x, transform.position.y + 5f, transform.position.z);
}