Hello,
I have added an ability to crouch in the game. The way I’ve done that is by changing the controller height and center y value. The issue is when I crouch to go underneath a platform the player still collides with the platform even though there’s clearly enough space.
If I set the controller height to the crouch height as the default height the player is able to go underneath the platform without trouble. Although, if I use the center offset the collision issue occurs.
bool isCrouching; float defaultHeight;
private CharacterController controller = null;
void Start()
{
controller = GetComponent<CharacterController>();
defaultHeight = controller.height;
}
void Update()
{
isCrouching = Input.GetKey(KeyCode.C);
}
void FixedUpdate()
{
DoCrouch();
}
void DoCrouch()
{
var height = isCrouching ? defaultHeight / 2 : defaultHeight;
controller.height = Mathf.Lerp(controller.height, height, 5 * Time.deltaTime);
controller.center = Vector3.down * (defaultHeight - controller.height) / 2.0f;
}
How do I fix this issue? Thank you