Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

After playing minecraft...

Discussion in 'General Discussion' started by jc_lvngstn, Oct 8, 2010.

Thread Status:
Not open for further replies.
  1. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    That looks a bit more like what you asked. Here are some good reads for achieving more realistic terrains:

    http://libnoise.sourceforge.net/tutorials/index.html (note there are 8 pages in that tutorial)

    http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html (start from section 1.3.3 if you don't care about marching cubes)

    To achieve the terrain that you want, you will have to do a lot of trial and error. Start from a base heightmap with 1 octave. Once you get it to look how you want it, add another octave, once you are happy with that, maybe add some warping, once you are happy, add 1 biome, so add 1 detail at a time, and test until you are satisfied. This way you get familiar with how to mix noises, and it is easier to get it to look how you want because you are only looking at 1 thing at a time.
     
  2. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    One thing I did is write a script to generate a bunch of combinations of noise, generate the voxels, take a 'screenshot' of the terrain, and save it to disk. Then I just had to leaf through a hundred or so results to see what looked the best.
     
  3. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I'm currently wondering how to show the cracks that appear on a block surface when it gets damaged. I could think of some fairly unwieldy solutions, but maybe there is a neat way of doing this?
     
  4. zDemonhunter99

    zDemonhunter99

    Joined:
    Apr 23, 2014
    Posts:
    478
    Replace the texture with a damaged one?
     
  5. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    This would work if every cube had it's own mesh; However, since every mesh of a chunk has dozens or hundreds of cubes, changing one textture would mean that the crack shows up on all surfaces that share the material. I'm working with submeshes for every unique material already, so I guess I could create a new decal material on the fly, put the original texture's main texture on it, and add the required crack decal. I was hoping that there is another way.
     
  6. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    Best way to handle this, and a common way, is to write a custom shader. Input is the block (for vectors), output is a new set of texture coordinates. Or input is the block "hp" (for pixels), output is the original texture pixels multiplied by the overlay. There are examples in this thread and there are a few others that are easily found via google.

    Your other option is to create a new mesh that sort of overlays just the cube in question, offset by like 0.01m, with a semi-transparent texture/material. And you'd make it invisible to raycasting and physics.
     
  7. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I see. I'll look around for a shader that takes the block's integrity value and returns an alpha value for the decal. Thanks!
     
  8. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    Love this thread, wish I would have looked for it/found it before I started on my own minecraft-like.

    Here is a video as if is now:


    I seem to be doing a good deal correctly for my first time doing this, and as of right now everything runs smoothly, runs at 60+ except when I update a ring of chunks and it goes down a few frames, but one thing I did not do is pool objects and I am instantiating and destroying all the time when you move. I did make sure that whenever I do that I don't do all of them at the same frame, so you really do not feel it, you only see it at a distance(mountains pop in, etc).

    I did something differently though, as for me it's mainly a 2 dimensional grid with height, and when you edit blocks they only lower by a bit. They also give you inventory, etc. I would like to eventually have terrain tiles change when you alter them, like grass giving away to dirt, etc.

    I see much talk of terrain generation, and this is one thing I definitely took my own approach to, as I only use some noise to get the slight undulations of sand and grass, everything else is done by hand with my own algorithm. It's completely random though I'd like to integrate seeding, and I recently read that you can use seeding in unity as easy as using random. You can see in the video I do a few restarts to get new terrain/island.

    Next up is adding caverns, which I have in the game now but is not video worthy yet! Here is a video of my testing of my algorithm along with some pathfinding test thrown in,
    , this one uses no noise, just this clumping algorithm I made along with some branching paths between the clumps.

    On to the question, one thing I would like to know and get input on is what is the best way to save this data. Right now I just spit out a brute forced text file with every block type and height listed, but I imagine with a humongous world like Minecraft that would be so big. I would imagine that if you seeded your world, you would just save the seed, regenerate the world, and only save the changed blocks, but even that over time would get huge. Maybe because I am saving as a text file it's slow and saving as binary or something else would be quicker?
     
  9. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    My approach: save the seed and only the blocks that changed with a RLE compression, 1 file per chunk.
     
    Hoshio likes this.
  10. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    Thanks goldbug, I'll look into this!
     
  11. shadbags

    shadbags

    Joined:
    Jul 14, 2014
    Posts:
    5
    Prime, got any more info on how you made that minimap? I've been trying to work out how to do something similar without mucking about with a second camera.
     
  12. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    Shadbags, it's just a texture I created using setpixels, whenever you click on the map icon it creates it, and only recreates it if you altered the world. It will cycle through the map block type array and paint it pixel by pixel. Mine is set to 2048x2048 so it has a slight delay when it creates it, but it allows you to zoom in nice and see the details, especially when the world is bigger like 1000x1000.

    The only other trick I am doing is sampling simple graphic tiles to lay down for the different type of blocks to make it look like an old drawn map(at least somewhat), before I did that I would just assign a color to each map block type and have the map system just plop down that color, but it looked bland.
     
    Last edited: Aug 29, 2014
  13. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    A second camera is actually the simplest solution, by far. There's no point in recreating the map from the data since you've already done that. Just point a camera at what you've already done. It doesn't have to be live, if performance is what you're worried about. Just use a RenderTexture.

    There's a good asset in the Store for this, actually.
     
  14. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    Well, this obviously works for many situations, but for a procedurally created world where only part of it exists at any time(the part nearest to the player), I don't know how it'd work.

    I also wanted to do something more stylized, which is a hand drawn map look, so I don't think rendering the a view of the world would work for that either.

    Depends on what Shadbags is after really.
     
  15. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I just thought about a different way of generating each face of a block. If the grid position xyz is known (the "lower left bottom", so to speak), wouldn't it be possible to somehow take the mesh from a prefab and use it for the block's face? I don't know if the UVs, vertexes, normals and triangles also have to be copied seperately. The idea is that one wouldn't be restricted to making simple 2-triangle faces by hand in script, but rather to use a detailed mesh from a model created properly in a 3d modelling application and use that one. Block faces could then look like the detailed walls and floors of, say, Legend of Grimrock.

    Edit: Of course, vertex count per chunk would be much higher, so chunks would be far smaller. The collision mehses would still be generated normally most of the time.
     
    Last edited: Sep 1, 2014
  16. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    Totally possible, though you are right, you run out of verts pretty fast depending on how detailed/dense the prefab is.

    Here is a test I just did:



    That terrain is generated on the fly based on a height map, then you see on the top row of images I used a unity sphere as a prefab and rebuilt it many times so that it conforms to the terrain, verts, uv's, normals and triangles. This works for any prefab as you can see by the capsule and cylinder part. This is all one mesh at the end, and this one is 10x10.

    The thing I would like to test is to see if I can get the prefab geo to actually 'deform' or 'skew' with the terrain inclinations, right now I am just averaging the verts for each polygon(2 tris) corner and using that as the height of the prefab I re-create.

    EDIT: got this to work.

     
    Last edited: Sep 1, 2014
  17. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Interesting. Did you use MeshCombine for the whole chunk?

    About the vertex count, I think it's more viable for dungeon crawler and the like which take place in comparatively smaller levels, notthe huge, open-ended environments of minecraft clones.
     
  18. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    No mesh combine, I just added the verts/normals/uvs/triangles for each one to their respective list before making the mesh, just applying the proper offsets and skewing to put them in place and mold them to the terrain.

    Yeah, not quite sure what you would use this for honestly, maybe like you said for some dungeon crawler, but you'd want to limit it each room so you would not have overdraw issues due to not being to cull things around corners, etc.
     
  19. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    It's been a while since my last post. But I started working on "BlockCraft" again, here a few screenshots (taken on my iPhone 5). Look out for BlockCraft on the app stores soon :)




     

    Attached Files:

    Last edited: Sep 3, 2014
    jc_lvngstn likes this.
  20. faraz

    faraz

    Joined:
    Aug 4, 2014
    Posts:
    46
    never played yet.
    but heard its awesome.. is it ?
    unity3diy
     
  21. magic9cube

    magic9cube

    Joined:
    Jan 30, 2014
    Posts:
    58
    Perhaps someone has some suggestions for this. How can i hide a skybox /background when inside a cave? See image for example; cave-sky.jpg
     
  22. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    This is a hack, but it is better than nothing:
    if the player is underground use a black skybox
     
  23. magic9cube

    magic9cube

    Joined:
    Jan 30, 2014
    Posts:
    58
    thanks for the suggestion. this was my first thought also. to adjust the skybox, i may need to adjust my terrain to allow this to work as some terrain has large overhanging areas which from a distance pose the problem where sky is visible but also 'cave' like sections under overhangs which extend beyond view range are visible also.
     
  24. shadbags

    shadbags

    Joined:
    Jul 14, 2014
    Posts:
    5
    pathfind out to the sky height, determine path length vs expected direct line length, scale skybox color based on ratio?

    I'd probably go brighter before going dimmer, so that you get the "bloom" effect of outside being too bright to look at whilst entering a cave / under a shadow, but then as you go deeper it disappears entirely.

    You can optimise the path find a bit. As soon as currently length hits "definitely underground" then set skybox to black. You can also pathfind out and up until you hit a ray of clear blocks upward.
     
  25. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515

    Coming back at this, I tried out copying the vertex, uv and triangle data from the mesh of an instantiated gameobject, and while it gives no errors, the mesh is all over the place or only a fraction of the triangles are generated.

    GameObject newObject = Instantiate(Resources.Load ("Models/SamplePrefab") as GameObject, transform.position, Quaternion.identity) as GameObject;

    Mesh customMesh = newObject.GetComponent<MeshFilter>().mesh;
    Destroy (newObject);



    foreach(Vector3 vertex in customMesh.vertices) {
    vertices.Add(vertex);
    }
    foreach(Vector2 uv in customMesh.uv) {
    uvs.Add(uv);
    }
    foreach(int triangle in customMesh.triangles) {
    triangles.Add(triangle);
    }

    vertexIndex += customMesh.vertices.Length;
     
  26. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    I think you have to offset the triangles by the vert count, or it will just keep on making the same tri's over and over.

    Try putting:

    int vertIndex = vertices.Count;

    at the top before the vert foreach, Then replace the triangle foreach with:

    foreach(int triangle in customMesh.triangles) {
    triangles.Add(vertIndex + triangle);
    }

    see if that works.
     
    Last edited: Sep 10, 2014
  27. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515

    Excellent, it works! Thank you very much.

    Here is my completed code in case anyone wants to use existing mesh data. At least it's handy for stairs and such that aren't much fun creating by script.

    Note that you might have to add a material assigning code, too (I use submeshes). I'm alsoo not sure how to directy Resource.Load a Mesh from a FBX file in the Resources folder so for now I'M just instantiating the whole gameObject, get the mesh, and destroy it.

    There's a seperate step included which takes the angleY variable from the xyz block class and rotates the mesh accordingly.

    GameObject newObject = Instantiate(Resources.Load ("Models/PlayerStart") as GameObject, new Vector3(x, y, z), Quaternion.identity) as GameObject;

    Mesh customMesh = newObject.GetComponent<MeshFilter>().mesh;
    Destroy (newObject);


    float angleY = chunk[x, y, z].angleY;
    Vector3 center = new Vector3(x + 0.5f, y, z + 0.5f);
    Quaternion newRotation = new Quaternion();
    newRotation.eulerAngles = new Vector3(0,angleY,0);

    int tempVertexIndex = vertices.Count;

    foreach(Vector3 vertex in customMesh.vertices) {
    vertices.Add(new Vector3(x + 0.5f + vertex.x, y + vertex.y, z + 0.5f + vertex.z));
    }

    for(int i = tempVertexIndex; i < vertices.Count; i++) {
    vertices = newRotation * (vertices - center) + center;
    }

    foreach(Vector2 uv in customMesh.uv) {
    uvs.Add(uv);
    }

    foreach(int triangle in customMesh.triangles) {
    triangles.Add(tempVertexIndex + triangle);
    }

    vertexIndex += customMesh.vertices.Length;
     
  28. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    Awesome, np.

    What kind of geo are you doing this on, more the minecraft stacked blocks, or terrain?
     
  29. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I'm currently creating a coop dungeoncrawler, it will combine the looks of Legend of Zelda/3D Dot Game Heroes with the gameplay mechanics of Skyrim. So, 3/4 view hack'n'slash in dark dungeons in a retro voxel look (I actually have copied the main hero from 3D Dot Game Heroes and a custom Blackmage character from Final Fantasy I) with lots of looting and button-mashing action. I'm currently building the dungeon during runtime by hand with my custom level editor but I plan to add a procedural random dungeon generation. I plan to have things like stairs and some larger decorative elements be part of the chunks, and only have smaller stuff as seperate gameobjects. That's why the mesh copying will come in handy.
     
  30. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    Sounds cool! I was wondering if you had any arbitrarily angled or stretched/sheared/skewed faces you needed to fit your meshes to, I have a algorithm for that.
     
  31. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I don't understand your question :)
     
  32. DandedIn

    DandedIn

    Joined:
    Sep 10, 2014
    Posts:
    8
    I think he renders cube only if one of those conditions are true:
    1. Higher Cube is Air
    2. Lower Cube is Air
    3. Cube to Left is Air
    4. Cube to Right is Air
    5. Next Cube is Air
    6. Cube Behind is Air
    But if all of them are false, cube is not rendered.
     
  33. DandedIn

    DandedIn

    Joined:
    Sep 10, 2014
    Posts:
    8
    And only renders cubes in chunks around you
     
  34. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Okay... I don't see any connection to any of the recent discussion here?!? :)

    What you say is true, of course... A face is only created if the cube next to it is empty.
     
    DandedIn likes this.
  35. DandedIn

    DandedIn

    Joined:
    Sep 10, 2014
    Posts:
    8
    I just recognized that there are 2k posts here :)
    I was answering first to the first post of this thread :)
     
  36. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I see. Have fun digging through the 51 pages then :p
     
  37. JohanHoltby

    JohanHoltby

    Joined:
    Feb 10, 2013
    Posts:
    89
    Hi all,
    Any good suggestions on how to handle when a block is removed on the border to an other chunk to avoid the skybox blinking through as the chunks get updated one after the other. If a block is blocking a block in the next chunk both the chunk containing the block need to be updated and the chunk adjacent (since a block needs to add a face).
     
  38. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    Depends on the code but generally speaking, add the necessary surfaces or update the mesh to block the players view of the skybox or other stuff that he is not supposed to see before you remove something in the game world.
     
  39. JohanHoltby

    JohanHoltby

    Joined:
    Feb 10, 2013
    Posts:
    89
    I agree but is there a best practice for this? I can think of maybe 5 different solutions and all have pitfalls and benefits. But in reality the most important is the feeling of the player. If you build all adjacent it takes time and the response is sluggish. Any good hacks or workarounds?
     
  40. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    One thing I do is to make sure not to build all of the chunks at the same time, same frame, etc, this spreads the workload out and you see less of a hitch. Just make an array of the chunks needed to update and just tick through them.

    I'd also recommend updating the adjacent chunk before the one you are currently on, as it'd hide any holes you would create, kind of like what Deon said.
     
  41. egamer13

    egamer13

    Joined:
    Aug 26, 2014
    Posts:
    9
    ugh my topic gets closed and takes me to this...
     
  42. JohanHoltby

    JohanHoltby

    Joined:
    Feb 10, 2013
    Posts:
    89
    Thank you.
    The order of build is a great idea. But if I'm adding blocks i must do it in the revers order. Correct? I would love to find a uniform simple way to build it all without ever make any "unnatural" gaps in the mesh.
     
  43. primemover

    primemover

    Joined:
    Jan 6, 2014
    Posts:
    11
    Oh yea, I guess it's a bit tricky, you'd want to update the chunk closest to you(or the one you are on) first for adding.

    Some tricks that might work, though I have done none of these in practice:

    1. Sounds like it takes long enough to update your chunks that this is a problem, so keying off the idea of spreading your chunk updates along different frames/times, you could also spread the chunk meshfilter update from the chunk meshcollider update across different frames/times, since it's slower. The only thing the delay would effect would be the selection/highlight of any blocks.

    2. Make a mesh that only has a meshfilter that includes only those faces you are altering, and just drag that along with you. It'd be light and update extremely quick, just update it first, and when you are done updating the other chunks, make it null or just an empty mesh object. There might be a slight visual change when those polygons are doubled up, but it might be better than a hole.
     
  44. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    The assigning of the (mesh)collider takes the most work, so you could try creating all meshes for the meshfilter first, and only once these are ready, assign the generated meshes to all meshcoliders.
     
  45. JohanHoltby

    JohanHoltby

    Joined:
    Feb 10, 2013
    Posts:
    89
    I currently uses a priority cue which builds them asynchronously using threads. But dividing the collide and the visual part was a good idea! The idea with parts which works as intermediate was an interesting idea.
     
  46. JohanHoltby

    JohanHoltby

    Joined:
    Feb 10, 2013
    Posts:
    89
    So I did add on collision script to the chunks and than added a inner trigger zone to the character or objects which is just a trigger. If that trigger is hit I move the object upwards.
    However i got another question. Since the chunks should have Rigidbodys connected with Rigidbody.isKinematic set to true to speed up the physics (avoid unnecessary calculations when moving the world to zero to avoid truncation errors). How do you avoid the problem when you have one plane as the only collider? I have tried to set the Rigidbody.inertiaTensor and Rigidbody.inertiaTensorRotation at all different position in code but i still get:

    Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually!
    UnityEngine.MeshCollider:set_sharedMesh(Mesh)
    .....
    The computation is preformed after the update in which i did set the new mesh and Tensors.

    I figure there must be a work around or a solution. I currently planing on adding a very small Tetrahedron under the first triangle in all meshes. This sound so bad as a solution but is my best shot.

    Any better solutions?
     
  47. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I was not aware that chunks should have kinematic rigidbodies. Where is the advantage in that?
     
  48. stulleman

    stulleman

    Joined:
    Jun 5, 2013
    Posts:
    44
  49. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
  50. leandroreschke

    leandroreschke

    Joined:
    Jan 8, 2014
    Posts:
    12
    What is the minimum hardware requirement on android? What type of lightning you use with torches, realtime lightning? A lot of torches will break performance? Depending on responses i will buy it.
     
Thread Status:
Not open for further replies.