Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
This question was closed Feb 28, 2017 at 07:53 PM by Krokozor for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Krokozor · Mar 01, 2017 at 07:16 AM · colliderscalechildspherematrix4x4

How do i get world position of collider if it inside multiple scaled gameobjects?

I want to get matrix wich will put vertices on sphere collider.

I wrote this:

     [ExecuteInEditMode()]
     [RequireComponent(typeof(SphereCollider))]
     public class SphereColliderTest : MonoBehaviour {
         Vector3[] _sphereVerts;
         int[] _sphereTris;
     
         SphereCollider col;
     
         void OnEnable() {
             col = GetComponent<SphereCollider>();
     
             GameObject primitive = GameObject.CreatePrimitive(PrimitiveType.Sphere);
             Mesh result = primitive.GetComponent<MeshFilter>().sharedMesh;
             _sphereVerts = result.vertices;
             _sphereTris = result.triangles;
             DestroyImmediate(primitive);
         }
     
         void Update () {
             Debuger.ClearGeneric();
             Vector3[] v = new Vector3[_sphereVerts.Length];
     
             Vector3 tScale = transform.lossyScale;        
             float r = Mathf.Max(Mathf.Abs(tScale.x), Mathf.Abs(tScale.y), Mathf.Abs(tScale.z)) * (col.radius / 0.5f);
             Vector3 cr = new Vector3(r, r, r);
             Matrix4x4 mr = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one) * Matrix4x4.TRS(Vector3.Scale(col.center, tScale), Quaternion.identity, cr);
             
             for (int i = 0; i < _sphereVerts.Length; i++) {
                 v[i] = mr.MultiplyPoint3x4(_sphereVerts[i]);
             }
     
             Debuger.AddWireMesh(v, _sphereTris, Color.blue);      
         }
     }

and, well, it actualy works just fine. but when i put sphere inside another scaled object i have no clue what unity does. how do i put vertices where i want in that case?

alt text

alt text

u1.jpg (106.2 kB)
u2.jpg (127.4 kB)
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 Krokozor · Feb 28, 2017 at 07:53 PM 0
Share

Oh. If anybody ever need answer: collider have BOUNDS. and bounds are actualy give all needed values

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How come certain Children don't cast an Overlapsphere? 1 Answer

How is localScale adjusted when re-parenting transforms? 2 Answers

how to scale object to fit inside a room 1 Answer

Sphere, internal collision 1 Answer

How should I scale an object with collider? 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