Well, I have searched for a solution and havent found any yet.
I’m using a raycast to check if the character gets grounded:
if(Physics.Raycast(transform.position+transform.TransformDirection(0,3,0),-transform.up,4))
grounded=true;
else
grounded=false;
Well, it works just fine when the character stands… When it falls it gets grounded and it wont strobe grounding and ungrounding while walking around on a terrain in different heights.
But, for some reason when I change the colliders height to half for crouching the character falls to the ground, the raycast still comes from above the terrain but it wont detect the ground anymore. ):
Crouching:
if(GetComponent<CapsuleCollider>().height!=6)
{
GetComponent<CapsuleCollider>().height=6;
}
The standings size is 12.
Does anybody knows why it wont detect the ground? Or any other method to make the character crouch which would propably fix this issue?