- Home /
How to crouch Smoothly
I've created crouch function for unity's fps controller and its working perfectly except one part and that is it's not smoothly crouching. By smoothly crouching I mean when the player crouches the character controller get smaller and the transition isn't smooth. Is there a way to smooth the transition between standing and crouching?
Here is my code:
public void Crouch()
{
if (isCrouching == false)
{
isCrouching = true;
characterController.height = 0.9f;
characterController.center = new Vector3(0, 0.3f, 0);
}
else if (isCrouching == true && !Physics.Raycast(transform.position, Vector3.up, 1))
{
isCrouching = false;
// move fps controller a bit up so it doesn't drop through the floor
FPSController.transform.Translate(0, 0.5f, 0);
characterController.height = 1.8f;
characterController.center = new Vector3(0, 0, 0);
}
}
Comment
Answer by Docter60 · Jan 29, 2020 at 12:05 AM
A form of linear interpolation is probably what you're looking for. Check out the answer here.
Your answer
Follow this Question
Related Questions
Why is my object not rotating smoothly ? C# 1 Answer
Move position with smoothing 0 Answers
Multiple Cars not working 1 Answer