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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Kyth'Pth3hk · Nov 05, 2013 at 08:46 PM · terraindebuggingvoxelchunk

Infinite terrain generation algorithm problems

Notice: This question is long winded, and anyone wanting to help will need to dig through a formidable amount of code looking for an obscure glitch. If you are faint of heart, please turn away now.

I had asked a question that is more or less identical to this one a few months ago, but lacking a sufficiant answer and unable to find an answer myself after several months of on and off trying, I am here to ask for help again.

I am making infinite terrain generation, and have come across a problem. It is block and chunk based (think Minecraft), and it is supposed to make a mesh for each chunk by putting adding 2 triangles for every face of a block that is facing air. However, it does not do this correctly, and oftentimes renders blocks that are surrounded by other solid blocks. The only pattern I see in the rendering error are as follows:

  • If the player shifts positively in the x-axis to prompt new chunks to be loaded, extra blocks seem to be loaded below the player with the quantity equal to how many chunks the player shifted.

  • If the player shifts negatively in the x-axis, no blocks are rendered.

Any help would be appreciated.

I have used the following link as a guide to the scripts, reading through it may help you understand how my code works. Guide

Below I have the links to the different files in the generation (in descending order of importance)

ChunkRenderer.cs World.cs terrainGen.cs Chunk.cs B.cs BlockTypes.cs DirtyType.cs AirType.cs PriorityQueue.cs

Also, the website of unity answers seems to have a long running feud with me, and as such I often am unable to perform certain actions in posts, such as replying to answers. Because of this, I may post answers to this question that are really just replies to their answers, so please refrain from having the mistaken notion that I am making tons of new answers because I don't know how the site works or that I'm just an asshat.

Comment
Add comment · Show 4
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 meat5000 ♦ · Nov 05, 2013 at 09:01 PM 0
Share

Yours was an interesting problem. All I can suggest is making a test case with numbers you can work out and read off the values in your arrays to make sure everything is running as you expect.

avatar image Kyth'Pth3hk · Nov 05, 2013 at 10:10 PM 0
Share

@meat5000:
Well it's just really hard to deter$$anonymous$$e what the values should and shouldn't be, unfortunately. Also, I did make some progress since last time I posted this. I had simply wrote logX ins$$anonymous$$d of sizeX or something like that in this one method, which I had overlooked. Unfortunately, that only solves part of the problem, not all of it.

avatar image flaviusxvii · Nov 05, 2013 at 10:31 PM 0
Share

Oh wow, your code scares the crap out of me. All of your triply-nested loops are fertile territory for any number of copy-pasta or off-by-one bugs that are notoriously difficult to debug.

You need to start thinking in terms of GameObjects! Logical units of the game world that are responsible for rendering and managing themselves. There isn't any reason you can't have Chunk inherit from $$anonymous$$onoBehaviour and decide whether it's too far from the player to be seen anymore and things like that.

avatar image Kyth'Pth3hk · Nov 09, 2013 at 03:50 PM 0
Share

@flaviusxvii: You may be right about that, although for most things I think "thinking in game objects" would make it even more difficult, such as knowing when to shift the chunk array... unless you're saying theres a way to do this without even having an array of chunks.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Kyth'Pth3hk · Nov 23, 2013 at 05:48 PM

Ok, so I've finally fixed the error. Turns out the values of the chunk.blocks array was wrong, due to the makeChunk method failing to assign the values of the blocks before it rendered the chunk, since the chunks blocks are only assigned after the method returns, while the chunk renderer needs them to be assigned before they return. I just changed the method from this:

Chunk makeChunk(World world, int cx, int cy, int cz, Texture2D texture) { Vector3 chunkAssignPos = new Vector3(); Chunk chunk = assignChunk(cx, cy, cz, ref chunkAssignPos, true); ChunkRenderer.render(world, ref chunk, cx, cy, cz, texture, chunkAssignPos); return chunk; }

into this:

void makeChunk(World world, ref Chunk chunk, int cx, int cy, int cz, Texture2D texture) { Vector3 chunkAssignPos = new Vector3(); chunk = assignChunk(cx, cy, cz, ref chunkAssignPos, true); ChunkRenderer.render(world, ref chunk, cx, cy, cz, texture, chunkAssignPos); }

And now it works. Thanks to everyone for trying to help. Wow, it took what, 4 months working on and off to find this? I must be the worst debugger ever. XD

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

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

Flowing water in my voxel terrain 1 Answer

Tiled Terrain 0 Answers

Optimization problems 1 Answer

How to make a voxel terrain generate all around the start point 1 Answer

Unloading Chunks not working 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