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 /
This question was closed Sep 13, 2020 at 04:45 AM by Rhyusaky for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Rhyusaky · Sep 10, 2020 at 02:26 AM · programmingtilemapprocedural generationchunksstrange

Big problem on chunk generation (Unity Tilemaps)

Why does this chunk generator, although it works virtually (in the sense that it generates chunks correctly, as seen in the gizmo img#0/img#1 visualization), generate these strange patterns in the tilemap?

img#0 alt text

img#1 alt text

The code for chunk generation here:

         Dictionary<Vector2Int, Chunk> chunks = new Dictionary<Vector2Int, Chunk>(32);
         public IEnumerator UpdateMap()
         {
             while(true)
             {
                 var cellSize = grid.cellSize;
                 var ppos = playerObj.transform.position;
                 ppos.x = ppos.x / (chunkSize.x * cellSize.x);
                 ppos.y = ppos.y / (chunkSize.y * cellSize.y);
                 var player = new Vector2Int(Mathf.RoundToInt(ppos.x), Mathf.RoundToInt(ppos.y));
                 Debug.Log(player);
                 string chunkReg = "*CHUNKS*";
                 for (int x = player.x - chunkArea.x; x <= player.x + chunkArea.x; x++)
                     for (int y = player.y - chunkArea.y; y <= player.y + chunkArea.y; y++)
                     {
                         var pos = new Vector2Int(x, y);
                         if (!mapBounds.Contains(pos) || chunks.ContainsKey(pos))
                             continue;
 
                         chunkReg += $"\n {pos}";
 
                         //var chunk = new Chunk(pos.x * chunkSize.x, pos.y * chunkSize.y, chunkSize.x, chunkSize.y);
                         var chunk = new Chunk(pos.x, pos.y, 1, 1);
                         chunk.Generate();
                         chunk.Draw();
 
                         chunks[pos] = chunk;
 
                         qtree.Insert(new Point(pos, chunk));
 
                         yield return null;
                     }
                 chunkReg += "\n END";
                 Debug.Log(chunkReg);
                 yield return null;
             }
         }

The code for the current chunk filling in tilemap:

         public void SetBlock(RectInt bounds, TileBase tile)
         {
             int xPos = bounds.x;
             int yPos = bounds.y;
             int w = xPos + bounds.width;
             int h = yPos + bounds.height;
 
             for (int x = xPos; x < w; x++)
                 for (int y = xPos; y < h; y++)
                 {
                     map.SetTile(new Vector3Int(x, y, 0), tile);
                 }
         }
         public void DrawChunk(Vector2Int position, bool draw)
         {
             var t = draw ? tile : null;
             //SetBlock(new RectInt(position.x * chunkSize.x, position.y * chunkSize.y, chunkSize.x, chunkSize.y), t);
             SetBlock(new RectInt(position.x * chunkSize.x, position.y * chunkSize.y, chunkSize.x, chunkSize.y), t);
         }

This problem doesn't seem to make any sense to me, do you understand? So ... if anyone knows any way to help me with this, I will be very grateful

img0.png (59.1 kB)
img1.png (24.3 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

1 Reply

  • Sort: 
avatar image
0

Answer by Rhyusaky · Sep 13, 2020 at 04:45 AM

I got the answer by trial and error.

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

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

Multiple Cars not working 1 Answer

Need help fixing procedural generation bug 1 Answer

How to assign individual data to a tiles? (Unity3D Tilemap) 0 Answers

Smooth chunk saving and loading 0 Answers

How to add tilemap to procedural generation 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