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 Mekuri · May 02, 2012 at 12:36 PM · proceduraltilealgorithm

My precedural Algorithm for Tidy TileMapper is not working!

I've recently bought Tidy Tilemapper, and I am now trying to create a procedural tile world with it. All I want is to remove any tiles too far away to be useful, and only show those close to my character. For testing purposes I have been using arbitrary numbers...

What I do (or am trying to do) is create a radius where I check all tiles within. I then have a smaller radius within that, and I remove everything there's outside the small radius, and inside the big radius. This way I avoid accessing the rest of the map, outside the big radius. Everything inside the small radius should be drawn to the screen. At the moment my map is pretty simple, if the value in the 2 dimensional array is 1, it should draw something.

When I launch the Scene I make the player a child of the Blockmap that is created. I then compare localPosition values to the position of the blocks. I think this is here my problem starts - Everything tile(block) that is created, are created towards the negative direction of Worldspace (and local space). I've messed around a lot with the following code on that account (I've burned out my brain :P). I'm spawning my player at X=0, and Y = half the height of the map. While I fall down to the map, if I move out in the positive direction on the X-axis (off the map) it will actually remove some of the tiles that it is supposed to. But it does not redraw any of them. If I move around on the world that is created for testing purposes, it does not remove anything in the "large radius", and doesn't create anything either.

I've taken the Perlin and level generation examples that are included in Tidy Tile Mapper, and modified them.

First off the Start and update methods, just so you can see the order of things. ConstructInitialWorld method prepares the Block Map, and creates the int array containing the map via the GetLevelMap method.

 // Use this for initialization
     void Start () 
     {
         ConstructInitialWorld();
     }
     
     void Update()
     {
         DrawMap();
     }

     //We'll construct the map here
     private void ConstructInitialWorld()
     {
         map = GetLevelMap(levelWidth, levelHeight);
                 
         //We'll go ahead and create our map now
         createdMap = BlockUtilities.CreateBlockMap(mapName,tileSize,chunkWidth,chunkHeight,BlockMap.GrowthAxis.Up);
         SpawnPlayer(new Vector2(0, levelHeight / 2));    
         
         //And now we refresh our map
         BlockUtilities.RefreshMap(createdMap,randomiseInitialMap);    
     }
 public int[,] GetLevelMap (int levelWidth, int levelHeight)
     {
         map = new int[levelWidth,levelHeight];
         
         //We will randomise the y value that we pass to the perlin function
         //This will result in a random level everytime
         float yOffset = UnityEngine.Random.value;
         
         for(int x =0; x < levelWidth; x++){
             
             //We'll get our perlin noise value -
             //normalizing our x to pass it as a parameter
             float p = Mathf.PerlinNoise((float)x/(float)levelHeight,yOffset);
             
             //Given this value, we'll get our height cap
             //And set it to allow for an empty column at the top, and 
             //assure it doesn't leave gaps in the bottom
             int ny = (int)(p * (float)levelHeight-2)+1;
             
             //Given this, we'll set all values below this number to be 'true'
             for(int y = ny; y < levelHeight; y++)
             {
                 map[x,y] = 1;
             }
         }
         return map;
     }

My guess is the problem is in the following code:

 private void DrawMap()
     {
         //Sets an arbitrary radius to "scan" around the player.
         for(int x = (int)pc.transform.localPosition.x - 30; x < pc.transform.localPosition.x + 30; x++)
             for(int y = (int)pc.transform.localPosition.y - 30; y < pc.transform.localPosition.y + 30; y++)
             {
                 if(x < pc.transform.localPosition.x - 10 || x > pc.transform.localPosition.x + 10 || y < pc.transform.localPosition.y - 10 || y > pc.transform.localPosition.y + 10)
                         BlockUtilities.RemoveBlockFromMap(createdMap, x, y, 0, false,true);
 
                 if(+x > map.GetLength(0) || +x < 0 || +y > map.GetLength(1) || +y < 0)
                     break;
                 if(map[+x,+y] == 1)
                 {
                     Debug.Log("If succeeded");
                     Block b = GameObject.Instantiate(blockPrefab) as Block;
                     
                     BlockUtilities.AddBlockToMap(createdMap,b,true,0,false,+x,+y,0, true, false);
                 }
                 else if(useEmptyBlocks)
                         BlockUtilities.AddBlockToMap(createdMap,null,true,0,false,+x,+y,0,true,true);
             }
     }

I know this is a heavy read, and thanks for reading it- But I really hope someone has an idea or can actually see what I am doing wrong.

Here's a link to a little documentation for Tidy TileMapper http://tools.dopplerinteractive.com/

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · May 02, 2012 at 01:26 PM

I don't have this toolkit, but it seems that it's already managed in chunks, so basically you should create / delete whole chunks instead of manipulating single block in those chunks...

It's actually very similar to the concept of minecraft ;) Just in case you haven't seen this yet, there is a free Minecraft starter package for Unity3d.

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 Bunny83 · May 02, 2012 at 01:28 PM 0
Share

Btw, it looks like you create your map array ahead of time, wouldn't it make more sense to generate the terrain when it's needed?

avatar image
0

Answer by Mekuri · May 02, 2012 at 04:36 PM

Nice, I will look into that package. I've already thought of operating in chunks, but there doesn't seem to be out of the box methods to add or remove chunks. But whether I figure out to handle it chunkwise or not, I'm still ending up with the same issues with my algorithm :)

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
avatar image
0

Answer by Mekuri · May 02, 2012 at 04:36 PM

Nice, thanks a lot for the link, I'll check it out.

I have already considered working in chunks, but I it seems there are no "out of the box" add or remove methods for chunks. I will probably do a method for this later, but this will not fix my currently bugged algorithm, that I've stared myself blind on :)

Thanks for the hints, I'll definately check out the Minecraft kit.

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

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

Lightmapping and Diablo3-style big-tile levels 1 Answer

2048 game moving tiles algorithm question 1 Answer

Procedural Texturing on Multiple Terrain Mesh 1 Answer

Lightmapping and Diablo3-style big-tile levels 0 Answers

How to create seemingly random arrangement of tiles in a grid? 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