Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 superflyninja · Jun 20, 2014 at 09:43 AM · prefabpositionbox collideralignment

Positioning Prefabs in exact positions

HI all, Im at my wits end here. Im sure its something simple that Im missing. Any help would be SUPER appreciated.

So I have a prefab,its called wall.It consists of an empty parent object, a super basic 3d mesh(imported from max) which is a wall section and a box collider that covers the wall mesh. What I want is to instantiate 4 of these in a square formation. The idea being to generate a few of these to build a tunnel.The problem is positioning the prefabs.They just dont fit together. The prefabs overlap. One odd thing, the scale of the mesh in the inspector is 0.0254(x scale for example),but the x scale of the collider is something like 59. Also the z offset of the collider centre is non zero for some reason,if I set it to zero then it doesnt cover the mesh . Here is the code I use to instantiate:

    float wallHeight = wall.transform.Find("Wall Side").GetComponent<BoxCollider>().size.y;
             float wallLength = wall.transform.Find("Wall Side").GetComponent<BoxCollider>().size.x * 
                 wall.transform.Find("Wall Side").localScale.x;
 
             Debug.Log("loopSidelength : " + wallLength);
     
             Vector3 p = new Vector3(0,0,0);
             
             //RHS
             p.x = centrePoint.x + wallLength/2f;
             p.y = centrePoint.y;
             p.z = centrePoint.z;
             GameObject right = (Instantiate(wall,p,Quaternion.Euler (0,270,0)) as GameObject);
             right.name ="Right";
     
             //LHS
             p.x = centrePoint.x - wallLength/2f;
             p.y = centrePoint.y;
             p.z = centrePoint.z;
             GameObject left = (Instantiate(wall,p,Quaternion.Euler (0,90,0)) as GameObject);
             left.name = "Left";
     
             //Top
             p.x = centrePoint.x;
             p.y = centrePoint.y;
             p.z = centrePoint.z + wallLength/2f;
             GameObject top = (Instantiate(wall,p,Quaternion.Euler (0,180,0)) as GameObject);
             top.name = "Top";
     
             //Bottom
             p.x = centrePoint.x;
             p.y = centrePoint.y;
             p.z = centrePoint.z - wallLength/2f
                 ;
             GameObject bottom = (Instantiate(wall,p,Quaternion.Euler (0,0,0)) as GameObject);
             bottom.name ="Bottom";
 
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

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

Answer by incorrect · Jun 20, 2014 at 11:32 AM

That is because your model made that way. It's center point does not match with center of collider (that is why z offset is not zero) and it's scale does not match collider's scale because your collider is probably something like 1 point x 1 point x 1 point in dimensions and model has different size. You should google how to set model's pivot point and scale and reimport it so it will match scale in Unity and it's center point will satisfy your needs. Also you can create empty GameObject and make your model it's child, positioning this proxy GameObject to the point you want to be center.

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 superflyninja · Jun 20, 2014 at 02:00 PM 0
Share

Cheers, yeah I removed the model and used a unity primitive ins$$anonymous$$d and all worked fine. Ill build using the primitives for now and revisit the models at a later date. Thanks!!

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

22 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

Related Questions

GameObject position and localPosition not changing in hiearchy, only in script. 0 Answers

BCE0019: 'position' is not a member of 'Object' 0 Answers

How I can update prefab properties using c# 1 Answer

Lerp to position in instantiated prefab? 1 Answer

How to set the UI Text position to be relative to his "grandfather" prefab 0 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