- Home /
Crouch jump bug.
Hi,i have crouch script it works perfect,i have fixed the un-crouching ceiling bug too,but when i crouch under the object,everything is perfect,but when i jump,i get a bit through that object..try yourself,please help me to fix this bug.
var controller : CharacterController; //ADD in Inspector
var isCrouched : boolean = false;
var checkCeiling : boolean;
function Update () {
if(Input.GetKey("c")){
if(!isCrouched) crouch();
}else{
if(isCrouched && !checkCeiling) stand();
}
if(isCrouched){
if(Physics.Raycast (transform.position, Vector3.up, 2.0)){
checkCeiling = true;
}else{
checkCeiling = false;
}
}
}
function crouch(){
controller.height /= 2;
isCrouched = true;
}
function stand(){
gameObject.transform.position.y += controller.height/2;
controller.height *= 2;
isCrouched = false;
}
Comment
Best Answer
Answer by harschell · Oct 13, 2012 at 09:01 AM
You create your own boolean variable to determine this, not all objects in Unity have an "enabled" member that you can check against. Your situation pretty much sums up the use case of a boolean flag. Boolean is "true / false" variable.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Player movement 0 Answers
Endless DeathZone??!!? 4 Answers
Action activates trigger. 1 Answer
Raycast Destroys player. 1 Answer