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 /
This question was closed May 25, 2018 at 01:03 AM by bpears for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by bpears · Jan 04, 2016 at 09:34 PM · c#colliderchildboundsboxcollider

How to set parent collider equal to child collider visually?

EDITED: Scale now works by diving parent scale. I am trying to make the parent collider conform to a selected child collider, that I assign in the inspector. However I can't quite get it's center to stay consistant. As you can see, the red parent and its blue child both have colliders. The childs own collider is correct and conforms to its own mesh, however, the parent using the script is the large collider outline seen. If I move the child, the parent collider will start surpassing its movement while I am wanting it to stay dead center of the child collider. I am trying to make the colliders match up perfectly according to child mesh.

 using UnityEngine;
 using System.Collections;
 
 [ExecuteInEditMode]
 
 public class ColliderToBounds : MonoBehaviour {
     public BoxCollider colli;
     public GameObject bound;
     private Bounds newbound;
     private Transform self;
         
     void Update() {
             self = colli.transform;
         newbound = bound.GetComponent<BoxCollider>().bounds;
         colli.size = new Vector3((newbound.size.x/self.localScale.x),(newbound.size.y/self.localScale.y),(newbound.size.z/self.localScale.z));
         colli.center = newbound.center - self.position;
     }
     
 }
 

alt text

asdfasdfasdf.jpg (23.4 kB)
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

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by bpears · Jan 05, 2016 at 12:06 AM

Thank the Math Gods, I got it. This is useful for setting up a parent with a collider that will be the same as the child.

 using UnityEngine;
 using System.Collections;
 
 [ExecuteInEditMode]
 
 public class ColliderToBounds : MonoBehaviour {
     public BoxCollider colli;
     public GameObject bound;
     private Bounds newbound;
     private Transform self;
         
     void Update() {
         self = colli.transform;
         newbound = bound.GetComponent<BoxCollider>().bounds;
         colli.size = new Vector3((newbound.size.x/self.localScale.x),(newbound.size.y/self.localScale.y),(newbound.size.z/self.localScale.z));
         colli.center = bound.transform.localPosition;
     }
     
 }
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 Meri · Mar 29, 2017 at 03:17 PM

This will stay correct until you rotate your object, rotation will break it up, but I think this might be of some use: http://answers.unity3d.com/questions/11210/re-calculate-aabb-after-rotating-a-mesh.html

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

Follow this Question

Answers Answers and Comments

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

How to access children's colliders. 4 Answers

Bounds with Rotation: Getting y value of the point where its on the most left side of the collider (bounds.min.x) Note that the box collider has been rotated as well. 2 Answers

Distribute terrain in zones 3 Answers

Leap Motion generated hand/finger is untagged. Reason? 1 Answer

Script detecting collisions of child object? 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