Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 VaporAnomaly · Jul 05, 2015 at 09:23 PM · primitivescapsulecast

Get capsule details (start, end, radius) from gameobject

Hi,

I have a capsule (invisible, without collider attached as a child to my camera). This was added in editor. I am planning to use CapsuleCast for certain collision related actions. My idea is, whenever I want to call capsule cast, instead of calculating the start and end of capsule to be used for CapsuleCast, I will just get them from the capsule primitive I attached to my camera and pass them to the CapsuleCast method.

Is it possible to get the details (Start, End, Radius) of the primitive I added in the editor, during game runtime?

Please let me know if my question/wording is not clear. Your answers are much appreciated.

Thanks.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Chrisdbhr · Jul 21, 2019 at 11:37 PM

Its possible to calculate these values (start, end) because the "radius" you already have.

To easier visualization, use this free asset called Debug Extensions that will be easier to you to draw it inside an OnDrawGizmos() monobehaviour method.

Store a reference to your CapsuleCollider on your MonoBehaviour script, than use this:

 public CapsuleCollider CapsuleColliderRef;

 private void OnDrawGizmos()
 {

     Vector3 startCapsulePos = transform.position + new Vector3(0f, CapsuleColliderRef.height/2f) + CapsuleColliderRef.center; /*this line gives you the capsule start position*/
     Vector3 finalCapsulePos = transform.position - new Vector3(0f, CapsuleColliderRef.height/2f) + CapsuleColliderRef.center; /*this line gives you the capsule end position*/
     DebugExtension.DrawCapsule(
         startCapsulePos,
         finalCapsulePos, 
         Color.blue,
         CapsuleColliderRef.radius /* here you have access to collider radius. */
         );
 }

This code considers that your capsule is on Y-axis direction. You will get something like this:

alt text

Ps.: I know it's an old question, but I decided to answers since I had this doubt and this is one of the first Google results.


unity-2019-july-21-08-32-pm.png (32.1 kB)
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
1

Answer by dgoyette · Apr 05, 2020 at 02:40 PM

The previous answer on this question seems to only work for vertical capsules. If you try it on arbitrarily rotated capsules, you'll get positions.

I've been using the Physics Extensions in this project: https://github.com/justonia/UnityExtensions/blob/master/PhysicsExtensions.cs

It contains a "ToWorldSpaceCapsule" extension method for getting the start, end, and radius of a capsule collider, regardless of the capsule's rotation.

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 JoeStrout · Apr 20, 2021 at 01:06 AM 0
Share

Thanks for the pointer to this code. It's exactly what I was looking for.

avatar image
0

Answer by Cherno · Jul 05, 2015 at 09:43 PM

The capsule used for the Primitive Type is just a regular mesh, there are no values for radius and length/height, except those which you would have to pull from the mesh' vertex data.

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
0

Answer by VaporAnomaly · Jul 10, 2015 at 08:35 AM

Thanks for the clarification. I calculated this is runtime. And after a while decided to use, colliders with triggers to get this done.

Thanks.

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

instantiating Transform insted of PrimativeType 1 Answer

Spawnning an object other than primitive makes the function run again and again 0 Answers

Capsule Cast Direction Help 1 Answer

Do Unity primitives incur performance penalties? If so, why? 0 Answers

Problem when manually creating game object in scene 3 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