This question was
closed Jul 15, 2016 at 07:20 PM by
Alatza for the following reason:
Problem is not reproducible or outdated
Question by
Alatza · Feb 29, 2016 at 11:48 AM ·
character controllercrouchcrouching
Crouching not nearly smooth enough
Hi guys,
No matter how much I fiddle with my code I can't get crouching/standing smooth enough. There is still a lot of stutter, mostly when standing back up.
I'm avoiding messing with scale because of the camera attached to the player.
Below is my code for crouching/standing
Please help. This is driving me nuts!
if (crouching)
{
newHeight = 0.9f;
speed = crouchSpeed;
}
else if (!crouching)
{
newHeight = 1.8f;
if (Input.GetButton ("Fire3"))
speed = runSpeed;
else
speed = walkSpeed;
}
float c_height = controller.height;
Vector3 c_center = controller.center;
float m_height = Mathf.Lerp(c_height, newHeight, 20f * Time.deltaTime);
controller.height = m_height;
c_center.y = (controller.height - c_height) / 2;
controller.center = c_center;
Comment
Follow this Question
Related Questions
[C#] playerHeight not working for FPS Controller 2 Answers
Unity 2D - Need Help Staying Crouched while Under Something 0 Answers
Camera offset when crouching 0 Answers
Cant move while Crouched 0 Answers
Should moving cameras have rigidbodies? 0 Answers