- Home /
Question by
melvinweert · Apr 28, 2021 at 08:37 PM ·
c#cameracrouching
Camera position when crouching
I'm currently working on a fp game but and I want the camera to move lower when crouching. I think im doing everything fine but for some reason it only works while pressen W and CTRL which makes you slide in my game but not when only crouching (only holding CTRL) here's my code:
if (Input.GetKey(KeyCode.LeftControl))
{
if (currentSpeed == 3)
{
isCrouching = true;
}
if (cc.isGrounded)
{
FPCamera.localPosition = new Vector3(0, 1.5f, 0);
if (Input.GetKey(KeyCode.W))
{
cc.height = 1f;
currentSpeed = currentSlideSpeed;
isSliding = true;
}
else
{
cc.height = 1f;
isCrouching = true;
isSliding = false;
currentSpeed = crouchSpeed;
}
} else if (!cc.isGrounded)
{
isSliding = false;
isCrouching = false;
currentSpeed = walkSpeed;
}
}
else if (!isBlocked)
{
isSliding = false;
isCrouching = false;
cc.height = 2f;
currentSpeed = walkSpeed;
FPCamera.localPosition = new Vector3(0, 2f, 0);
}
Comment
Your answer

Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
WorldToScreenPoint 0 Answers
Camera spinning and error/bug 2 Answers
How is LOD implemented? 3 Answers