Hey. I’m trying to make a first person game with the player needing to crouch under objects but I want the players standing height to be depending roof.
if (Input.GetButton("Crouch"))
{
player.height -= 1;
IsCrouched = true;
if (player.isGrounded == true)
{
Speed = CrouchSpeed;
JumpForce = CrouchJumpForce;
}
}
else
{
player.height += 1;
IsCrouched = false;
Speed = WalkSpeed;
}
player.height = Mathf.Clamp(player.height, 4, 8);
this is the code I’m using so far however the player instead clips through the ground slightly preventing me from moving.
let me explain what I’m trying to achieve a little better,
When the player pressed crouch, the character will decrease height until it reaches its minimum height of 4, when the player releases crouch, the character will increase height until it reaches one of two outcomes,
1: the player reaches it’s highest height value of 8
2: the roof is preventing to character from getting any taller
I hope this explains what I want to achieve and if anyone knows how to fix it, please help me
T-T