Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by gszauer · Apr 02, 2011 at 07:56 PM · drawgizmocapsule

Draw Capsule Gizmo

I want to draw a wireframe capsule gizmo, kinda like this:

void OnDrawGizmosSelected() {
    Gizmos.color = Color.green;
    Gizmos.DrawWireSphere(transform.position, 5.0f);
}

Just a capsule. Not a sphere. Is there an easy way to do this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Scribe · Apr 02, 2011 at 08:58 PM

Class Variables color Sets the color for the gizmos that will be drawn next. matrix Set the gizmo matrix used to draw all gizmos.

Class Functions DrawRay Draws a ray starting at from to from + direction. DrawLine Draws a line starting at from towards to. DrawWireSphere Draws a wireframe sphere with center and radius. DrawSphere Draws a solid sphere with center and radius. DrawWireCube Draw a wireframe box with center and size. DrawCube Draw a solid box with center and size. DrawIcon Draw an icon at world position in the scene view. DrawGUITexture Draw a texture in screen coordinates. Useful for GUI backgrounds.

these are the only things that gizmos allow for so no ther is no easy way of having a wire frame capsule

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
5

Answer by toomasio · Jan 14, 2019 at 03:05 PM

Created a static method if people need.

 public static void DrawWireCapsule(Vector3 _pos, Quaternion _rot, float _radius, float _height, Color _color = default(Color))
     {
         if (_color != default(Color))
             Handles.color = _color;
         Matrix4x4 angleMatrix = Matrix4x4.TRS(_pos, _rot, Handles.matrix.lossyScale);
         using (new Handles.DrawingScope(angleMatrix))
         {
             var pointOffset = (_height - (_radius * 2)) / 2;
 
             //draw sideways
             Handles.DrawWireArc(Vector3.up * pointOffset, Vector3.left, Vector3.back, -180, _radius);
             Handles.DrawLine(new Vector3(0, pointOffset, -_radius), new Vector3(0, -pointOffset, -_radius));
             Handles.DrawLine(new Vector3(0, pointOffset, _radius), new Vector3(0, -pointOffset, _radius));
             Handles.DrawWireArc(Vector3.down * pointOffset, Vector3.left, Vector3.back, 180, _radius);
             //draw frontways
             Handles.DrawWireArc(Vector3.up * pointOffset, Vector3.back, Vector3.left, 180, _radius);
             Handles.DrawLine(new Vector3(-_radius, pointOffset, 0), new Vector3(-_radius, -pointOffset, 0));
             Handles.DrawLine(new Vector3(_radius, pointOffset, 0), new Vector3(_radius, -pointOffset, 0));
             Handles.DrawWireArc(Vector3.down * pointOffset, Vector3.back, Vector3.left, -180, _radius);
             //draw center
             Handles.DrawWireDisc(Vector3.up * pointOffset, Vector3.up, _radius);
             Handles.DrawWireDisc(Vector3.down * pointOffset, Vector3.up, _radius);
 
         }
     }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ATLGAN · Jan 26, 2019 at 01:43 PM 0
Share

Thanks for this useful code :)

avatar image
1

Answer by Orr10c · Mar 04, 2018 at 10:05 AM

I might be alittle late, ok VERY late but I figured out a way to do this pretty easily and wanted everyone to have a solution to this: I used the Gizmos.DrawMesh function and assigned a capsuled shaped mesh (which unity has as a default 3D shape) to a variable of my script and then sent that variable as a parameter to the DrawMesh function and I could pretty easily mess with the size and radius of the capsule.

works great for me, hope it helps anyone.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PixelFireXY · Jun 22, 2021 at 01:59 PM 0
Share

Nice thought, thanks!

avatar image Sebasian · May 14 at 06:10 PM 0
Share

a small a code example would help alot. I have no idea how to create a capsule mesh via code.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Console error when trying to use gizmos? 2 Answers

How to draw a Sprite on OnDrawGizmos() 0 Answers

Using Gizmos.DrawWireCube to draw position bounds? 1 Answer

Drawing capsule gizmos and keeping it with the object scale 2 Answers

where are the icons for Gizmos.DrawIcon? 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges