- Home /
How does CharacterController visualize its collider?
I'm writing my own character controller that doesn't use a rigidbody. Since my controller "creates" it's own collider it doesn't rely on the character object actually having a collider component. Still, for obvious reasons I want to visualize the collider, and I noticed that unity's default CharacterController somehow does this. Even though there is no collider component added to the object the character controller itself visualizes the collider.
I read somewhere that the default CharacterController IS a collider, but as far as I know scripts that are added to objects need to derive from MonoBehaviour.
Any ideas on how to achieve this?
Answer by EyadThedevelopingBoi · Jun 05 at 01:40 PM
You will need to use Gizmos, There is no draw capsule function so you will need to use the other functions to make a cylinder
The documentation on Gizmos: https://docs.unity3d.com/ScriptReference/Gizmos.html
Forum post talking about drawing a capsule with gizmos: https://forum.unity.com/threads/drawing-capsule-gizmo.354634/
@Babooh: Note you said:
Even though there is no collider component added to the object the character controller itself visualizes the collider.
This is not true. The CharacterController component IS a collider. Look at the documentation. At the top you see the base class from which CharacterController is derived from. It's derived from Collider.
The character controller acts like a static collider in regards to the physics system. Though if you want to emulate the same thing it's kinda tricky. Moving a collider component without a rigidbody is bad for performance because colliders without a rigidbody are expected to never move. The CharacterController is an exception as it's implemented in native code.
Though if you just want to visualize it, Gizmos are the way to go.
Your answer
Follow this Question
Related Questions
Collision CharacterController vs CharacterController 2 Answers
How to deal the 2d platform physics? 0 Answers
Randomly some prefab instances have Character controller misaligned 0 Answers
Picking up items with Rigidbodies 2 Answers
Character Controller OnControllerColliderHit never called. 0 Answers