Create a Crouching System

preview_player
Показать описание
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
isCrouching = true;
Actions.Sitting(true);
}

if (isCrouching && !crouchbutton)
{
//try to stand up

if (!cantStandUp)
{
isCrouching = false;
Actions.Sitting(false);
}
}
}
Рекомендации по теме
Комментарии
Автор

The only good crouch tutorial on youtube. Thanks!!!

yumbo
Автор

Great video on helping me with the Raycast up to detect whether the character can stand or not :)

Noseyk
Автор

Nice tutorial. Can you pls help me because in my game i want to make my character crouch when the CNT button is pressed. Pls reply what can I do

vedpurohit
Автор

error CS0246: The type or namespace name 'Actions' could not be found (are you missing a using directive or an assembly reference?)

IMARIDERR
Автор

Your all tutorials are very good & understandable. Can you create a game update system?

manishotaval
Автор

someone please tell how to swap the sci-fi character used in the above series with my own character.. I need the same functions that the sci-fi soldier can do onto my own character... Please help, i'm into my first project in unity and need help !!

akashraj
Автор

but when u go under a surface is alittle bit upper than ur player, player can stand and it is a bug

olodurin
Автор

NO OVERLOAD ERROR FIX
For those who receive the error "no overload methods Sitting takes 1 argument"
when they use Actions.Sitting(false) and Actions.Sitting(true)

SOLUTION
Go to the Actions Script on the Sci-Fi Soldier delete the entire
public void Sitting() and change it to this.

public void Sitting (bool sitting) {
animator.SetBool ("Squat", sitting);
animator.SetBool("Aiming", false);
}

Found this fix in his project files, too bad he forgot to show
it in the tutorial.

treasureimpact
Автор

I have a problem in the console Assets / Scripts / Third Input / OwnThirdPersonController.cs (59, 21): error CS1501: No overload for method `Sitting 'takes` 1' arguments
Can you help me please

martinelton
Автор

Error no over load methods ' sitting' takes 1 argument.

.please help

Deba-M
Автор

If anybody faces the issue where the character stops standing up then check the ignore raycast on your characters layer. Thought I might save someone's hours. Just wasted 3 hours of mine.

muaazanas
Автор

Does this work for 1st Perserin and to the 3D Tutorial from brackeys

fisicious
Автор

Why don't you send your example projects to github? It would be veeery helpful

ugvdudv
Автор

you chanel is super cool please tutorial 2d card game tutorial pocket mortys clone tutorial

martin
Автор

2:43 You wrote "croch" instead of "crouch"!

hriday