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 Pete-El · Dec 17, 2013 at 02:16 PM · transformmesharrayrotatedirection

Updating new cube face positions after rotation

Hi,

I have a game object with a box collider that has a child with a mesh. I rotate the mesh at 90 degree intervals around the x y & z axis but keep the parent objects rotation locked. This makes up a building block which is stored as a prefab. There are multiple types of this prefab but they all follow this format, mainly just the mesh changes.

I connect blocks to each other (all building blocks become children of a single parent) however some block types cant accept another block on a certain face. I have a script "ConnectorControllerScript" attached to each building block that stores an array of 6 booleans that correspond to the Up, -Up, Forward, -Forward, Right and -Right directions.

To place new blocks, I have another script which shows a transparent building block in the place of where the new one is going to go. This allows you to rotate it around the x,y,z axis before placing it. When the block is instantiated I set the rotation of the mesh to a quaternian.identity as for some reason meshes were being instantiated with rotation applied despite the mesh child having zero rotation on any axis in the prefab. I then rotate the mesh to the same position as the transparent building block.

So far so good, thanks for reading this far...

Now after the block is instantiated I need to rotate the positions the ControllerConnectorScript array represents to match the new building block orientation.

To achieve this I check the meshes up direction and compare that to the 6 world directions (i.e. Vector3.up, -Vector3.up, Vector3.right etc) Depending upon which one it hits, it returns a an index in an array corresponding to the new cube faces position. I repeat this process for each mesh directions and swap out the positions as shown in the code.

At least that's what it should do. It kinda works and the array is updated but the updated positions being in the right position have a success rate of about 50% and I've been hitting my head against this one for the last 3 nights.

I've attached the code that does the checking. I've tried a few other methods but I just can't seem to crack this one.

Thanks for taking the time to look at this one!

     void updateFaceConnections(GameObject mesh){
         bool[] tempBool = new bool[6];
         for (int i = 0; i < 6; i++)
             tempBool[i] = connections[i];
 
         connections[NewFaceIndex(mesh.transform.up)] = tempBool[0];
         connections[NewFaceIndex(-mesh.transform.up)] = tempBool[1];
         connections[NewFaceIndex(mesh.transform.forward)] = tempBool[2];
         connections[NewFaceIndex(-mesh.transform.forward)] = tempBool[3];
         connections[NewFaceIndex(mesh.transform.right)] = tempBool[4];
         connections[NewFaceIndex(-mesh.transform.right)] = tempBool[5];
 
     }
 
     int NewFaceIndex(Vector3 direction){
 
         if (direction == Vector3.up)
             return 0;
         else if (direction == -Vector3.up)
             return 1;
         else if (direction == Vector3.forward)
             return 2;
         else if (direction == -Vector3.forward)
             return 3;
         else if (direction == Vector3.right)
             return 4;
         else if (direction == -Vector3.right)
             return 5;
         else
             return -1;
     }
Comment
Add comment · Show 2
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 robertbu · Dec 17, 2013 at 03:24 PM 0
Share

Are you getting -1 back or just the wrong index?

avatar image Pete-El · Dec 17, 2013 at 08:45 PM 0
Share

Just the wrong faces unfortunately. The -1 is there to force an exception error so I know if some really bad happens.

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

transform.rotation problem 1 Answer

Problem with the look direction after Instanciate/Rotate 0 Answers

Rotate Around Object 2 Answers

Rotating a transform using it's child 2 Answers

can anyone tell me why this doesn't work? 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