Create a Crouching System @DitzelGames
Create a Crouching System  @DitzelGames
Uploaded June 2018 | Updated September 2026, 7 hours ago
I will show you how to create a Crouching System in Unity. You can use this for sitting or stealth action in your game. The hardest part is to prevent a the player to stand up, when he is under an object. We will prevent this by a raycast up. Have fun!

Code:

protected bool isCrouching = false;
protected CapsuleCollider CapCollider;

private void Crouch()
{
var crouchbutton = CrouchButton.Pressed || Input.GetKey(KeyCode.C);

if (!isCrouching && crouchbutton)
{
//crouch
CapCollider.height = 0.5f;
CapCollider.center = new Vector3(CapCollider.center.x, 0.25f, CapCollider.center.z);
isCrouching = true;
Actions.Sitting(true);
}

Debug.DrawRay(transform.position, Vector3.up * 2f, Color.green);
if (isCrouching && !crouchbutton)
{
//try to stand up
var cantStandUp = Physics.Raycast(transform.position, Vector3.up, 2f);

if (!cantStandUp)
{
CapCollider.height = 1f;
CapCollider.center = new Vector3(CapCollider.center.x, 0.5f, CapCollider.center.z);
isCrouching = false;
Actions.Sitting(false);
}
}
}
Create a Crouching SystemUnity Game Slow? Performance #2 - PhysicsWhy I quit #MMAG - Reading CommentsWerde der beste Börsen Trader!Full Enter Car Animation Tutorial in Unity | MMAG #13Animations with Unity Shader GraphCreate Octave Water Waves - Unity Ocean Tutorial 1/4Data Structures Challange at HackerRank.com - Lets Code #004Ludum Dare 42 - SubmissionUnity Tutorial Build Support - Q&ASoccer Battle Royale | Steam TrailerUnity Keynote in 7 Minutes - Summary of Unite LA 2018
DitzelGames |

Create a Crouching System

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER