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 Noiz · Mar 31, 2015 at 10:49 AM · c#voxel

Voxel Dictionary Lookup Issues

Thanks in advance for reading and any suggestions you have! I realize this problem is very specific, but I'm hoping I either don't understand dictionaries or I've overlooked something obvious. Any help will be greatly appreciated!

I'm trying to make a voxel engine just for fun. I have been extending Voxity (from the asset store) with concepts and modified code from http://alexstv.com/index.php/category/voxels

My dictionary of chunks uses the chunk's transform position as its key. Finding a chunk uses this:alt text

Any value greater than chunk size gets rounded up to the next possible chunk position. Any thing lower gets floored to the next lowest possible chunk position (works for negatives as well). This succeeds every time. I have never had it return the wrong value for a chunks position in the world.

The issue I'm having (as far as I can tell at the moment) is that the lookup fails, returning null chunks at incomprehensible times (to me at least. I tried debugging but I didn't learn anything I didn't already see: I'm getting null chunks returned at odd times [I used mono to debug, not Debug.Log]).

Here are some missing faces:alt text

Despite the fact that the neighboring chunks exist (as verified in the editor by checking neighboring positions), the look up fails sometimes, but succeeds most of the time.

The blocks of a chunk are stored in a [16,16,16] array. I use this to determine when to draw a face (its ugly):

 if (x + 1 >= chunkSize) //ie, x > 15, the outer bound of the array
 {
     Vector3 newX = new Vector3(nX + 1, nY, nZ);  //nX is the chunk's position + x
  
     if (World.GetChunk(newX) != null && World.GetBlock(newX).index == 0) // It fails here. 
     DrawFace(x+1,y,z,Vector3.up,Vector3.forward, true, chunk[x,y,z].index); 
 }
 else if (chunk[x+1,y,z].index == 0) // We are within array bounds, so just check the block
     DrawFace(x+1,y,z,Vector3.up,Vector3.forward, true, chunk[x,y,z].index);
 


The face doesn't draw when if its neighbor is null. If i remove this check, EVERY face gets drawn every time. Since the chunk is null, asking a block for its index will return 0 (I assume), meaning the face is drawn.

This confuses me even more. I'm not even sure whats going on. The Vector3 key always seems to be correct, yet the look up fails at odd time! Unless I don't check for null chunks, then it always fails? Obviously I've got the wrong idea of what is actually happening. If you can, please help me out!

faces.png (389.3 kB)
code.png (12.5 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

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

What is a simple way to make a voxel face? 1 Answer

How do I calculate this voxel script so I don't get a out of range error? 2 Answers

Making a bubble level (not a game but work tool) 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