- Home /
Can't see CharacterController gizmo unless its GameObject is selected
I'm working through the Penlope tutorial, and it asks you to create a standin object and scale it down to fit into a GameObject named player that has a CharacterController attached. But I can't see the CharacterController's capsule shape while I have the Standin object highlighted for scaling. If I select the GameObject that has a CharacterController, then I can see the wireframe capsule.
Now in this case, I could go back and forth and iterate several times until I get the size right, but I could see this becoming a real hassle if I'm doing it repeatedly in a real project. How can I make the CharacterController visible always in the Scene view?
EDIT: Thanks! That does it. I modified it some to include whatever offset is set for the center of the CharacterController. This is in JavaScript.
@script RequireComponent( CharacterController )
function OnDrawGizmos() {
var cc : CharacterController = GetComponent(CharacterController);
Gizmos.color = Color.green;
var gizmoPos = new Vector3(transform.position.x+cc.center.x,transform.position.y+cc.center.y,transform.position.z+cc.center.z);
if(cc.height > cc.radius *2)
Gizmos.DrawWireCube(gizmoPos, new Vector3(cc.radius * 2, cc.height, cc.radius * 2));
else //if (cc.radius * 2 > cc.height || cc.radius * 2 == cc.height)
Gizmos.DrawWireSphere(gizmoPos, cc.radius);
}
Answer by StylizeR · Jan 09, 2012 at 07:20 AM
You can draw a Gizmo so you will always know how high/wide it needs to be scaled.. Just put this C# script on the GameObject:
using UnityEngine;
using System.Collections;
public class CharacterControllerGizmo : MonoBehaviour {
void OnDrawGizmos() {
CharacterController cc = GetComponent<CharacterController>();
Gizmos.color = Color.yellow;
if(cc.height > cc.radius *2)
Gizmos.DrawWireCube(transform.position, new Vector3(cc.radius * 2, cc.height, cc.radius * 2));
else //if (cc.radius * 2 > cc.height || cc.radius * 2 == cc.height)
Gizmos.DrawWireSphere(transform.position, cc.radius);
}
}
But since you can't set DrawWireSphere's height, you'll have to draw a WireCube when the CharacterController radius*2 is smaller than CharacterController height.. But I think it does the job..