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 Kyth'Pth3hk · Aug 31, 2013 at 11:46 PM · errordebugginginfinite terrain

Infinite terrain generation algorithm problems

I've been trying to track down a cause of an error in some code for several days now, and I just can't seem to find it. Normally I would try to find which variables are not as they should be, and then use the "wolf fence algorithm" to find exactly where the cause is, but I have no way of knowing when variables are wrong or not in this case. I've tried checking all the variables I can, and they all seem to be correct.

The problem isn't the wrong normals. When the player moves, new chunks are loaded, towards where the player is walking, making the world "infinite". The problem is the chunks are often being loaded... incorrectly. I'm not sure how to describe it, but the blocks are in the wrong places, making floating chunks, and large cliffs between some chunks. It's best if you just try it yourself by moving the character controller to new locations and watch how the new chunks get created.

Code can be found at http://pastebin.com/XBgb1kwy. To get it working, just add a character motor tagged "Player", and a gameObject with the "terrainGen" script attacked. You will also need to save the priorityQueue and chunkVec scripts as assets. No console output happens whatsoever.

Comment
Add comment · Show 21
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 cdrandin · Aug 31, 2013 at 11:53 PM 1
Share

Post it on a form such as answers.unity3D.com or unless you have signed some contract restricting you from doing this then I would ask other people who are working on the project for you. Else try to come up with a problem simpler to yours and post that on a form and see if it translate to your problem. Errors typically require fresh set of eyes to help you see.

avatar image Kyth'Pth3hk · Sep 01, 2013 at 12:05 AM 0
Share

@cdrandin:

Are you sure The community would be willing to do that? The script is pretty long (~800 lines) and I don't know of any way to simplify it more than it already is. Also, sorry for making this an answer ins$$anonymous$$d of a comment, but I can't, nor ever have been, able to find the "add comment" button.

avatar image DannyB · Sep 01, 2013 at 03:08 PM 0
Share

Seems like you already have a good grasp of your debugging process, it would be hard to help you solve your problem with this information.

When you say you have an error - can you elaborate on its nature? Do you see anything in the console or not? If so, it will help a lot.

Since you did not mention it, I am guessing there is nothing in the console, but rather an unexpected behavior in your game. These are harder to find, but I can tell you that in addition to trying and fence the wolf, one other technique I have used in harder cases, is to start removing code so that you are left with only the essential bits that reproduce the error.

avatar image meat5000 ♦ · Sep 01, 2013 at 03:24 PM 0
Share

Sin/Cos/Tan and degrees/radians, double negatives, populating and Out of bounds arrays, ==0 (or other round number when its actually a float), parsing, dot product 90º, ROUNDING error, vector3.angle direction.

All good places to debug when looking for an error. Unity loves rounding error. It adds it in everywhere. ==whole number is a nightmare.

Tell us what the error is and we can all sit here shouting stuff out like playing charades.

Dropbox your code. I'll take a look at it. I'm sure others will have a stab too. Just don't recommend CODESTOR$$anonymous$$ING it onto a QA page :P

avatar image Jamora · Sep 01, 2013 at 03:58 PM 0
Share

I might take a look at the code as well, if made available. Just remember to tell us what the problem is specifically. Searching for a non-specified non-syntax error in ~800 lines of code will not be succesful.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fherbst · Sep 01, 2013 at 06:37 PM

The only thing I can see at once that's missing is the normals of the cubes, thus the lighting is wrong. This can be fixed by simply moving the mesh.RecalculateNormals() call further down:

 Mesh mesh = new Mesh();
 mesh.vertices = vertices.ToArray();
 // mesh.RecalculateNormals(); // this is too early
 mesh.uv = uvs.ToArray();
 mesh.triangles = triangles.ToArray();
 mesh.RecalculateNormals(); // triangles are needed before normals can be calculated
 mesh.RecalculateBounds(); // I would do this as well

Then it looks like this:

alt text

[OP said that the normals weren't the original problem]

The problem definitely lies within your GenerateChunks and ShiftLoadedChunks method (moving the player and calling Generate all the time works as expected). I would start by trying to restate your algorithm in a way that doesn't involve try-catch as integral part of the solution.

Also, I don't know why you need that priority queue and 1-s-generating-delay at all. I think you could just go through your chunks, delete the ones not matching the player position anymore, and generating new ones on the opposite side. If that's too resource intense, I would add exactly that objects to the generating queue and generate them one at a time after sorting by distance to the player (you seem to currently have quite a complicated way of doing that - you should think about your data structure).

[1]: /storage/temp/14963-screenshot01-09-2013+20.29.50.png


screenshot01-09-2013 20.35.49.png (66.0 kB)
Comment
Add comment · Show 3 · 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 Kyth'Pth3hk · Sep 02, 2013 at 12:10 AM 0
Share

@felix: I've gotten rid of the try-catch blocks, and the error hasn't seemed to change. That still was a good suggestion though because the exception handling was expensive. SOme things I've noticed on the chunk generation glitches is that it only generates wrong if you add more chunks to the chunks-to-load queue while there are already chunks in it. So, if you move in a direction, then stop and wait for all the chunks to load before moving again, the error doesn't occur. Could that have something to do with it?

Cheers.

avatar image fherbst · Sep 02, 2013 at 12:25 AM 0
Share

Like I said: you should think about your storage structure (right now, I find it quite inconvenient to access a chunk's position from the world array) and match the thing you're doing in the Generate method (which works fine) and the thing you're doing in the other methods (that produce glitches).

avatar image Kyth'Pth3hk · Sep 02, 2013 at 06:10 PM 0
Share

@felix: What do you mean by " the thing you're doing in the Generate method"? Both the Generate method, and the other methods use ChunkRenderer.render and assignChunk methods.

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

20 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

Related Questions

Why am I getting NullReferenceException on my .Contains()? 1 Answer

"Build failed. Method not found: 'Int32' 1 Answer

"Build failed. Method not found: 'Int32' 0 Answers

What are Asserts for? 1 Answer

3rd party bug reporting system similar to unity's "Report A bug" 3 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