x


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);
}
more ▼

asked Jan 09 '12 at 04:21 AM

tenfour gravatar image

tenfour
1 2 2 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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..

more ▼

answered Jan 09 '12 at 07:20 AM

StylizeR gravatar image

StylizeR
51 2 3 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x670
x69
x29

asked: Jan 09 '12 at 04:21 AM

Seen: 590 times

Last Updated: Jan 11 '12 at 01:23 AM