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 /
  • Help Room /
This question was closed Aug 29, 2017 at 02:30 PM by Phelyz for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Phelyz · Apr 05, 2017 at 09:47 AM · collider3d model

Issue with fbx box collider

Hi,

In my project I have to instantiate a fbx model and add a box collider on it, based on children's bounds (because the parent is an empty gameobject). I used the following code (picked up from other answers):

 public class CreateBoxCollider : MonoBehaviour {
 
     void Start () {
         Quaternion currentRotation = this.transform.rotation;
         this.transform.rotation = Quaternion.Euler (0f, 0f, 0f);
 
         Bounds bounds = new Bounds (this.transform.position,  Vector3.zero);
 
         foreach (Renderer renderer in GetComponentsInChildren<Renderer>()) {
             bounds.Encapsulate (renderer.bounds);
         }
 
         Vector3 localCenter = bounds.center - this.transform.position;
         bounds.center = localCenter;
 
         this.transform.rotation = currentRotation;
 
         BoxCollider bc = this.GetComponent<BoxCollider> ();
         bc.center = localCenter;
         bc.size = bounds.size;
     }
 }

The problem is that the box collider created on the parent with this script is much bigger than the model. Here's the result : alt text

The y size seems right, but is there a reason why x and z sizes aren't ?

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

1 Reply

  • Sort: 
avatar image
0

Answer by TailKitty · Apr 06, 2017 at 09:24 AM

@Phelyz

Is it really necessary to create box colliders dynamically?

Just make a prefab out of your FBX model and add appropriate box collider on every single bone in your model which you need directly in the editor.

After, just instantiate your ready to go prefab instead.

Note: use void OnTriggerEnter(Collider col) event to detect collision instead of OnCollisionEnter to avoid some strange mismatches with collisions. It gives me a lot of troubles then I was using OnCollisionEnter event instead...

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 Phelyz · Apr 06, 2017 at 10:03 AM 0
Share

Yes it's necessary to create box colliders dynamically because I'm not supposed to know the model that will be instantiated. The user can add any FBX model of his choice in Assets/Resources.

I already tried to add a box collider on every bones, and it worked, but I want to create a box collider that completely encompasses the model because I have to manipulate the model with Leap $$anonymous$$otion and it will be much simpler this way. Plus, the FBX $$anonymous$$odel may have hundreds of pieces so...

The Leap $$anonymous$$otion manipulation script only works with void OnTriggerEnter by the way.

Follow this Question

Answers Answers and Comments

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

Dice going through walls using Raycast hit distance 0 Answers

Rotating Object When Clicked and Rotating Back When Clicked Again C# 1 Answer

Player passing through walls when in corners 0 Answers

Changing light color between players when they collide (BOLT) 0 Answers

How to find the distance between unknown object and player 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