FPS Controller Duck

Hey

I’m making a FPS and now i want to make the First Person Controller duck. Now i have the problem that i can’t access the collider of it although it clearly has one.

Player.collider didn’t work and Player.GetComponent(“CapsuleCollider”) also didn’t.

Can someone pls help me?

The CharacterController has its own capsule collider. You don’t have direct access to it, but can modify its characteristics with the CharacterController properties center, radius and height.

I answered a question some time ago that does that (and implements run and crouch speeds too): How to Make the FPS Character Controller RUN and CROUCH. It’s a simple script added to the First Person Controller that communicates with CharacterMotor.js and set its variables to do the trick. Ducking is actually implemented via transform.scale.y modification, thus the FPS camera automatically follows the new height.

Everyone who also has a problem with ducking. Here’s the script I use:

var Player : GameObject;
var PlayerCharContr : CharacterController;

PlayerCharContr= Player.GetComponent("CharacterController"); //in Start function

if(Input.GetButtonDown("Duck"))
{
	if(DuckSwitch)
	{
		Player.transform.position.y+=1.001;
		PlayerCharContr.height+=0.5;
		PlayerCharContr.center.y-=0.25;
		DuckSwitch=false;
		print(DuckSwitch.ToString());
	}
	else
	{
		
		PlayerCharContr.height-=0.5;
		PlayerCharContr.center.y+=0.25;
		DuckSwitch=true;
		print(DuckSwitch.ToString());
	}

}

The credit for the way to do it goes to Aldo.