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 Spiderbean · May 07, 2014 at 05:15 PM · terrainmeshvoxeldeformationmarching cubes

Marching Cubes terrain deformation problem

Hello Guys,

I am trying to follow this thread a bit and you guys have been a great help. I am at the moment developing a marching cubes terrain. I started off with a normal Voxel Minecraft terrain, which worked out perfecly well. It is hard for me to read through the entire thread, so I thought I would post my problem: My terrain engine is supposed to help edit chunks, which worked perfectly well on my blocky version of it. Although now if I click often nothing happens and the chunks appear to be edited only sometimes(only if the colliders have a certain shape). I've tried everything I could think of. Subtracting the hit.normal didnt work. Tell me if you need more scripts.

``

 using UnityEngine;
 using System.Collections;
 
 public class PlayerIO : MonoBehaviour {
     public int viewRange;
     public float intRange;
     public Chunk ChunkPrefab;
     public static int width {
         get { return World.thisWorld.chunkWidth; }
     }
     public static int height {
         get { return World.thisWorld.chunkHeight; }
     }
     void Start() {
         if(viewRange == 0) viewRange = 30;
         StartCoroutine(UpdatePos1());
         StartCoroutine(UpdatePos2());
     }
     void Update() {
         if(Input.GetMouseButtonDown(0)) {
             StartCoroutine(RemoveBlock());
         }
     }
     IEnumerator RemoveBlock() {
         Ray ray = camera.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray,out hit, intRange)) {
             Vector3 p = hit.point;
             Chunk chunk = Chunk.FindChunk(p);
             if(chunk == null) return false;
             float x=p.x-chunk.transform.position.x, y =p.y,z =p.z-chunk.transform.position.z;
             int a = Mathf.FloorToInt(x), b = Mathf.FloorToInt(y), c = Mathf.FloorToInt(z);
 
             if(x < width -1 && z < width -1) {
             chunk.data[a,b,c]=0f;
             chunk.data[a+1,b,c]=0f;
             chunk.data[a,b,c+1]=0f;
             chunk.data[a+1,b,c+1]=0f;
 
             }else if(x == width - 1 && z == width -1 ) {
                 chunk.data[a,b,c]=0f;
                 Chunk chunk1 = Chunk.FindChunk(new Vector3(x+chunk.transform.position.x+2,y+chunk.transform.position.y,z+chunk.transform.position.z+2));
                 chunk1.data[a-width,b,c-width] = 0f;
                 StartCoroutine(chunk1.UpdateAt());
                 Chunk chunk2 = Chunk.FindChunk(new Vector3(x+chunk.transform.position.x+2,y+chunk.transform.position.y,z+chunk.transform.position.z));
                 chunk2.data[a-width,b,c]=0f;
                                StartCoroutine(chunk2.UpdateAt());
                 Chunk chunk3 = Chunk.FindChunk(new Vector3(x+chunk.transform.position.x,y+chunk.transform.position.y,z+chunk.transform.position.z + 2));
                 chunk3.data[a,b,c-width] = 0f;
                                StartCoroutine(chunk3.UpdateAt());
                 StartCoroutine(chunk.UpdateAt());
             }else if(x == width - 1 ) {
                 chunk.data[a,b,c]=0f;
                 chunk.data[a,b,c+1]=0f;
                 Chunk chunk1 = Chunk.FindChunk(new Vector3(x+chunk.transform.position.x+2,y+chunk.transform.position.y,z+chunk.transform.position.z));
                 chunk.data[a-width,b,c]=0f;
                 chunk.data[a-width,b,c+1]=0f;
                 StartCoroutine(chunk1.UpdateAt());
             }else if(z == width - 1 ) {
                 chunk.data[a,b,c]=0f;
                 chunk.data[a+1,b,c]=0f;
                 Chunk chunk1 = Chunk.FindChunk(new Vector3(x+chunk.transform.position.x,y+chunk.transform.position.y,z+chunk.transform.position.z+2));
                 chunk.data[a,b,c-width]=0f;
                 chunk.data[a+1,b,c-width]=0f;
                 StartCoroutine(chunk1.UpdateAt());
             }
             StartCoroutine(chunk.UpdateAt());
             if(x == width -1 || z == width -1) {
                 StartCoroutine(chunk.UpdateAt());
             }
             if(x <= 1) {
                 Chunk atchunk = Chunk.FindChunk(hit.point - new Vector3(2,0,0));
 
                 StartCoroutine(atchunk.UpdateAt());
             }
             if(z <= 1){
                 Chunk atchunk = Chunk.FindChunk(hit.point - new Vector3(0,0,2));
 
                 StartCoroutine(atchunk.UpdateAt());
             }
             if(z <= 1 && x <=1){
                 Chunk atchunk = Chunk.FindChunk(hit.point - new Vector3(2,0,2));
                     
                 StartCoroutine(atchunk.UpdateAt());
             }
 
         }
         
         yield return 0;
     }
     IEnumerator UpdatePos1 () {
         while(viewRange > 0){
             for(float x = transform.position.x - viewRange;x < transform.position.x + viewRange; x += width ) {
                 for(float z = transform.position.z - viewRange;z < transform.position.z + viewRange; z += width ) {
                     Vector3 pos = new Vector3(x,0,z);
                     pos.x = Mathf.Floor(pos.x / (float)width) * width;
                     pos.z = Mathf.Floor(pos.z / (float)width) * width;
                     
                     Vector3 delta = pos - transform.position;
                     delta.y = 0;
                     if(delta.magnitude > viewRange) continue;
                     
                     
                     Chunk chunk = Chunk.FindChunk(pos);
                     if(chunk != null) continue;
                     chunk = (Chunk)Instantiate(ChunkPrefab, pos, Quaternion.identity);
                     yield return new WaitForEndOfFrame();
                 }
 
         }
         yield return new WaitForSeconds(0.5f);
     }
         yield return 0;
     }
     IEnumerator UpdatePos2 () {
         while(viewRange > 0){
             for (int a = 0; a < Chunk.chunks.Count; a++) {
                 Vector3 pos = Chunk.chunks[a].transform.position;
                 Vector3 delta = pos - transform.position;
                 delta.y = 0;
                 if(delta.magnitude < viewRange) continue;
                 Destroy(Chunk.chunks[a].gameObject);
                 yield return new WaitForEndOfFrame();
             }
             yield return new WaitForSeconds(3);
         }
         yield return 0;
         }
 }


terrain.png (389.2 kB)
Comment
Add comment · Show 2
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 Spiderbean · May 11, 2014 at 06:55 PM 0
Share

I started debugging and using all sorts of normals and other stuff to correct the raycasting. It just doesn´t work! Here I use the Debug.DrawLine . You can clearly see that the $$anonymous$$athf.FloorToInt works(in order to get 3D array index). But it still randomly not work there.

alt text

terrain.png (92.1 kB)
avatar image Tion-Gaming · Feb 03, 2015 at 02:10 AM 0
Share

Do you think you can make that 2d?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Norrin · Aug 18, 2014 at 07:51 PM

Not quite an answer but a tip. Lynda has a great marching cubes tutorial and implementation in this course. Its chapter 5, I believe.

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 Wolfzie · Mar 11, 2015 at 12:07 AM

Not quite sure on your Generation Files but i can give you a hint. Check to make sure you are using a "Mesh Collider" not a Box collider on your prefab and when you do the raycasting make it find the block attached to the mesh collider. Its possible you are missing the box collider because some of the faces may have been occulled.

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

23 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

Related Questions

Shader: Mesh with Grass and Wind 1 Answer

Where should I start on creating a procedural generated terrain that can be deformed? 0 Answers

How to add materials to a tessellated plane? 0 Answers

Can a dynamic mesh be made NOT readable? to save mem 1 Answer

Smooth Voxel terrain. How is it done? 2 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