- Home /
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?
Answer by aldonaletto · May 05, 2012 at 03:32 PM
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.
Answer by ExTheSea · May 05, 2012 at 04:17 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613071124im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help: A collider attached to the character controller of a FPS does not collide 1 Answer
fps controller problems 1 Answer
Physics objects sliding along surfaces 1 Answer
Colliding for my character 2 Answers
Objects not jumpable on 2 Answers