- Home /
Camera jitters when getting up from croutch
I'm making a crouch mechanic for an fps game and mechanically it works well enough, but when I exit crouching the camera jitters a bit because the entire charactercontroller jitters. How can I make this smooth?
if (isCrouching)
{
characterController.height = Mathf.Lerp(characterController.height, 1.0f, Time.deltaTime * crouchTransitionDuration);
characterController.center = Vector3.Lerp(characterController.center, new Vector3(0, 0.5f, 0), Time.deltaTime * crouchTransitionDuration);
transform.position = new Vector3(transform.position.x, transform.position.y - 5f, transform.position.z);
}
else
{
characterController.height = Mathf.Lerp(characterController.height, 2.0f, Time.deltaTime * crouchTransitionDuration);
characterController.center = Vector3.Lerp(characterController.center, new Vector3(0, 0, 0), Time.deltaTime * crouchTransitionDuration);
transform.position = new Vector3(transform.position.x, transform.position.y + 5f, transform.position.z);
}
Answer by YagirX · Oct 26, 2021 at 10:29 PM
You need to make the camera and physics separate. You can create a player's object, put a collider into it, separately create a camera object (these 2 objects are children of the player). Then calculate the point where the camera should be located and do camera.localpos = Vector3.Lerp (camera.localpos, localCamraPoint, time * Time.deltaTime).
Your answer
Follow this Question
Related Questions
How to make player crouch smoothly, PLZ HELP !!!! 2 Answers
Detect collision when changing character controller height 2 Answers
Crouching makes my player unable to move. 2 Answers
How can I make my FPS player move towards the direction it is facing 1 Answer
Why character start to go by himself after the build level? 2 Answers