- Home /
failing to access height of a capsuller collider
im trying to access height of a capsuler collider so that i can use it with in a function but i keep getting this error Custom_scripts/CH_Controller.js(20,70): BCE0019: 'height' is not a member of 'UnityEngine.Collider'. below is an extract of my code
if(Physics.Raycast(transform.position,-transform.up,collider.height/2 + 0.2))
{
isGrounded=true;
Jumping= false;
inAir=false;
}
i later tried defining height as below but it also didnt work
function Start () { var robotCollider = gameObject.GetComponent(CapsuleCollider);
}
function FixedUpdate () { if(!isGrounded){ if(Physics.Raycast(transform.position,-transform.up,robotCollider.height/2 + 0.2)) { isGrounded=true; Jumping= false; inAir=false; } ``}
Answer by whydoidoit · Oct 27, 2012 at 08:31 AM
Ah you are skirting around the answer :)
So you correctly guessed that collider isn't going to be a capsule collider (and therefore doesn't have the height variable) - actually it is a capsule collider but the way you are accessing it the compiler doesn't know that.
(collider As CapsuleCollider).height
Will give you the height (presuming collider is a CapsuleCollider, otherwise it's a null reference)
Your GetComponent was a good idea - but you defined it as a local variable - so that approach you should have made it a private class variable. Basically FixedUpdate doesn't have a robotCollider in it!
var robotCollider : CapsuleCollider;
function Start()
{
robotCollider = GetComponent(CapsuleCollider);
}
You just might find some of the information in this tutorial useful.
Your answer
![](https://koobas.hobune.stream/wayback/20220613082937im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Charactor Controller Collision 0 Answers
Terrain collider slow framerate at height 0 Answers
Appear and Dissapear: Fog 1 Answer
Check for collisions with script outside of object with collider 0 Answers
collider doesnt react to script 0 Answers