Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Benjames · Feb 29, 2016 at 08:22 PM · colliderlocalpositionradiusautomaticspherecollider

AddComponent conforms to shape, size, position of mesh. How do I do this manually?

I have a small marching cubes set that changes size shape and position on runtime, relative to its objects relative space. When I delete the objects spherecollider then add a new spherecollider the local center position and radius conform to the mesh generated by marching cubes. The problem is destroying the spherecollider then adding a new one just to change the size and position of the sphere is pretty inefficient IMO.

What is a good way to set the SphereCollider's position and size the same way it is set automatically?

Comment
Add comment · Show 1
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 Benjames · Feb 29, 2016 at 08:25 PM 0
Share

alt text

Here is a screenshot. Its not very helpful but O'well

screeny.jpg (92.0 kB)

2 Replies

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

Answer by Bunny83 · Feb 29, 2016 at 08:46 PM

The problem you just have discovered is called the "minimal bounding sphere". Unfortunately there's no easy reliable way to obtain / calculate that sphere. See Algorithms for some implementations. In most cases it's enough to calculate an approximate solution since an exact solution can be very CPU intensive and it gets worst the most points you have.

edit

Just found this old question with was about the very same thing.

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 Benjames · Mar 01, 2016 at 01:07 AM 0
Share

Thanks for the response

avatar image
0

Answer by Benjames · Mar 01, 2016 at 06:14 PM

So I whipped something up based on your response "Bunny83". It's an approximation I suppose, since it doesn't take into account all the vertices in the mesh. Also while comparing distance from center it uses only what has been checked. But alas "Most of the time is good enough."

 Vector3 Center=Vector3.zero;
 float Furthest=0;
 int numberchecked=0;
 for(int tt=0; tt<vc; tt+=7)
 {
     numberchecked++;
     Center+=vertices[tt];
                 
     float dd=((Center/numberchecked)-vertices[tt]).magnitude;
     if(dd>Furthest)
     {
         Furthest=dd;
     }
 }
 
 coll.radius=Furthest-.13f;
 coll.center=(Center/numberchecked);

  
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

42 People are following this question.

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

Related Questions

Keep SphereCollider radius the same, even though scale is changed 2 Answers

Unity - Object hiting soon the other object 0 Answers

3D game: Pickups don't disappear when player touches them. 4 Answers

Increase the radius of Unity's primitive sphere? 1 Answer

Internal collisions 1 Answer


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