• 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 gabrielpda · Oct 06, 2020 at 09:04 PM · minecraftblocksgaps

How remove block mesh gap

I'm creating a minecraft based world, but i came across a problem.
When I generate the world, it becomes like the image with this little gap between blocks.
How i remove it?

alt text


I'm creating each quad individually and then combining it in a single chunk.

This is the code used to combine:

 private void CombineQuads()
 {
     var meshFilters = Object.GetComponentsInChildren<MeshFilter>();
     var combine = new CombineInstance[meshFilters.Length];
 
     for (int i = 0; i < meshFilters.Length; i++)
     {
         combine[i].mesh = meshFilters[i].sharedMesh;
         combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
     }
 
     var mf = Object.AddComponent<MeshFilter>();
     mf.mesh = new Mesh();
 
     mf.mesh.CombineMeshes(combine);
 
     MeshRenderer renderer = Object.AddComponent<MeshRenderer>();
     renderer.material = TextureAtlas;
 
     foreach (Transform quad in Object.transform)
     {
         GameObject.Destroy(quad.gameObject);
     }
 }


And this what i use to create each single quad:

 private void CreateQuad(CubeSide side)
 {
     var mesh = new Mesh
     {
         name = side.ToString() + "QuadMesh",
     };
 
     var p0 = new Vector3(-0.5f, -0.5f, 0.5f);
     var p1 = new Vector3(0.5f, -0.5f, 0.5f);
     var p2 = new Vector3(0.5f, -0.5f, -0.5f);
     var p3 = new Vector3(-0.5f, -0.5f, -0.5f);
     var p4 = new Vector3(-0.5f, 0.5f, 0.5f);
     var p5 = new Vector3(0.5f, 0.5f, 0.5f);
     var p6 = new Vector3(0.5f, 0.5f, -0.5f);
     var p7 = new Vector3(-0.5f, 0.5f, -0.5f);
 
     switch (side)
     {
         case CubeSide.Bottom:
             mesh.vertices = new Vector3[] { p0, p1, p2, p3 };
             mesh.normals = new Vector3[] {Vector3.down, Vector3.down,
                                     Vector3.down, Vector3.down};
             break;
         case CubeSide.Top:
             mesh.vertices = new Vector3[] { p7, p6, p5, p4 };
             mesh.normals = new Vector3[] {Vector3.up, Vector3.up,
                                     Vector3.up, Vector3.up};
             break;
         case CubeSide.Left:
             mesh.vertices = new Vector3[] { p7, p4, p0, p3 };
             mesh.normals = new Vector3[] {Vector3.left, Vector3.left,
                                     Vector3.left, Vector3.left};
             break;
         case CubeSide.Right:
             mesh.vertices = new Vector3[] { p5, p6, p2, p1 };
             mesh.normals = new Vector3[] {Vector3.right, Vector3.right,
                                     Vector3.right, Vector3.right};
             break;
         case CubeSide.Front:
             mesh.vertices = new Vector3[] { p4, p5, p1, p0 };
             mesh.normals = new Vector3[] {Vector3.forward, Vector3.forward,
                                     Vector3.forward, Vector3.forward};
             break;
         case CubeSide.Back:
             mesh.vertices = new Vector3[] { p6, p7, p3, p2 };
             mesh.normals = new Vector3[] {Vector3.back, Vector3.back,
                                     Vector3.back, Vector3.back};
             break;
     }
 
     mesh.uv = Block.UVs.TryGetValue(side, CubeSide.Front).ToArray();
     mesh.triangles = new int[] { 3, 1, 0, 3, 2, 1 };
 
     mesh.RecalculateBounds();
 
     var quad = new GameObject("Quad");
     quad.transform.parent = Parent.Object.transform;
     quad.transform.position = Position;
 
     var meshFilter = quad.AddComponent<MeshFilter>();
     meshFilter.mesh = mesh;
 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Oct 06, 2020 at 11:15 PM

It's hard to tell from the single screenshot. The issue is most likely a rendering issue. Though since Unity now supports several render pipelines and countless different shaders we can't really suggest much at this point. It could be an issue with your mipmaps. Do you use an atlas texture? If so are your tiles of a power of two size? Also what filtering method does the texture use? The Minecraft texture atlas doesn't require any padding space between tiles because it uses point filter mode and ensures to sample the center of a texel rather than the edge / corner.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

136 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 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 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 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 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 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

Help with placing and destroying blocks 1 Answer

How to texture blocks in a way similar to Minecraft? 3 Answers

Saving Scenes and loading GameObjects? 4 Answers

Help! Saving blocks in a grid-based building system 0 Answers

problem with gap at specific radius 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges