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 iloveaphextwin · Dec 07, 2011 at 10:00 AM · arraytilestransitionscorner

Rotate corner tiles with bitwise method

Hi there,

I have a level described by an array. This array is then filled with gameObjects.

 private var levelArray:int[] = [7,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,
                                 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
                                 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
                                 0,0,0,0,1,1,1,1,1,1,6,6,1,1,1,1,0,0,0,0,
                                 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
                                 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
                                 0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
 
 var width = 20;
 var length = 20;
 var pieces: GameObject[ , ];
 pieces = new GameObject[width, length]; // creates the object array
       
 for(z=0; z<length; z++){
     for(x=0; x<width; x++){
         var prefab: GameObject;
         prefab = blockPiece[levelArray[z*width + x]];
         // Add piece to stage
 
         pieces[x,z] = Instantiate (prefab, Vector3(x,1,(z*-1)), Quaternion.Euler(0, 180, 0));
 
         cP = levelArray[z*width + x];
         print(cP);
     }
 }

I can't figure out how to automatically rotate the corner pieces of my level. I need some kind of for loop that checks the surrounding numbers in the array.

Please help

Will

Comment
Add comment · Show 7
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 Bunny83 · Dec 07, 2011 at 12:33 PM 0
Share

It looks like you don't use special corner pieces... how should they be rotates? You have "1"-tiles at straight edges negative and positive corners. I can't imagine a tile (which have to be rotated) to fit in all of these positions...

Do you have screenshots of your different tiles?

To do this automatically it's not that easy. The main problem is to deter$$anonymous$$e what's supposed to be inside and what's outside. This can be done by checking the 8 surounding pieces.

It might be much easier when you just use some more prefabs for each rotation (should be only 4) and define them accordingly.

avatar image Statement · Dec 07, 2011 at 12:46 PM 0
Share

Yeah, need more information about what a rotated corner piece is for instance would better help us to help you.

avatar image iloveaphextwin · Dec 07, 2011 at 02:51 PM 0
Share

Thanks for the comments.

I basically have an island with sand, water and corner piece blocks. The corners have id's at the moment 3, 4, 5, 6. They are not defined in the code but each corner or diagonal piece will be set to the id of a diagonal bit. I want to avoid na$$anonymous$$g all these in the map array, so that those edges are worked out automatically.

I have seen it done and it's referred to as the bitwise method, but I have no idea how to implement it. I need to generate a code for each number in the array that describes the 8 surrounding blocks and then I'll check those codes against a list somehow??

avatar image iloveaphextwin · Dec 07, 2011 at 02:57 PM 0
Share

I basically need to implement this

http://www.gamedev.net/page/resources/_/technical/game-program$$anonymous$$g/tilemap-based-game-techniques-handling-terrai-r934

avatar image iloveaphextwin · Dec 07, 2011 at 02:58 PM 0
Share

Although $$anonymous$$e is simpler as I just want corners and diagonals.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a 2d array of gameObjects 2 Answers

Help with arrays, multidimensional 0 Answers

How do you calculate walls between tiles in a 3d environment? 5 Answers

Array of Tilemaps misbehaving 1 Answer

Push down GUI everytime for loop cycles through Array 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