- Home /
Is a CharacterController.collider a CapsuleCollider?
I tried this code sample, but it doesnt seem to work:
CapsuleCollider ccol ; if (collidercomp.GetType() == typeof(CapsuleCollider )) { CapsuleCollider ccolcaps = collidercomp as CapsuleCollider; ccol = ccolcaps; Debug.LogWarning("GameObject: " + go.name + " has a Capsule Collider"); } else { CharacterController ccolchar = collidercomp as CharacterController; if(ccolchar == null) Debug.LogWarning("GameObject: " + ccolchar.name + " is null - charCont"); if(ccolchar.collider == null) Debug.LogWarning("GameObject: " + ccolchar.collider.name + " is null - collieder");
ccol = ccolchar.collider as CapsuleCollider;
if(ccol == null)
Debug.LogWarning("GameObject: " + ccol.name + " is null - caps");
Debug.LogWarning("GameObject: " + go.name + " has an implicit Capsule Collider from CharacterController");
}
Answer by Senhor de todo o Mal · Feb 11, 2011 at 05:31 PM
A CharacterController is a subclass of Collider. CapsuleCollider is also a subclass of Collider.
But they are not the same, you can cast CharacterController or CapsuleCollider to Collider, but you cannot cast between them.
Look for documentation about Inheritance if you want to learn more.
Your answer
Follow this Question
Related Questions
Character falls thru to his waist 11 Answers
CharacterController bugged? Linecast not hitting top/bottom 0 Answers
Collision Detection in Capsule Collider 0 Answers
Mecanim Rigidbody character slope limit issue 1 Answer
Changing character's capsule collider's height based on its model's height 0 Answers