Search Unity

  1. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  2. Unity 2017.1 is now released.
    Dismiss Notice
  3. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  4. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

After playing minecraft...

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

  1. codeman_nz

    codeman_nz

    Joined:
    Jul 30, 2015
    Posts:
    11
    Thanks. I've used it and it looks like there is a spike in Gfx.WaitForPresent.
     
  2. CorWilson

    CorWilson

    Joined:
    Oct 3, 2012
    Posts:
    47
    So will mesh.vertices = new array of vertices always cause a slight freeze in gameplay? I'm constantly updating terrain meshes due to lighting and water algorithms running. All the calculations are done on other threads in C# code, then applied to the main thread to only apply them. I'm updating several chunks at a managed time, but that one line seems to always cause the gameplay to freeze while applying it.

    This is the one problem in getting my game to work. My chunks are all 16 x 16 x 16, instead of the usual 16 x 16 x 128, and I only update neighboring chunks depending on the block that was updated. Then the lighting updates in the same manner, while water updates in each chunk it's going through every iteration. Again, these are all put on a queued timely process, so they only process every x seconds, x being whatever I want it to be.

    So there is no overhead happening on the main thread except for mesh.vertices of each affected chunk getting their new array of vertices. I need to somehow make this work flawlessly on a low cpu hardware.
     
  3. codeman_nz

    codeman_nz

    Joined:
    Jul 30, 2015
    Posts:
    11
    I love Unity and think it's a great engine but I don't think it's suited for this task. So I'm going to create my own game.
     
  4. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
    Wait, wait, are you using MeshFilter.mesh??
    That might be a problem. IIRC that actually creates a copy of the mesh internally. Try constructing a new mesh, setting it to dynamic, and set that mesh to the sharedMesh field. Then just update that mesh's vertices. Then you don't have to assign the mesh every time (meaning you can get rid of that GetComponent call every time the mesh is updated) and it will not create a whole new mesh every time.
     
  5. CorWilson

    CorWilson

    Joined:
    Oct 3, 2012
    Posts:
    47
    My world is fixed size, so there's no chunks being initiated after the world is loaded. Once they are created, their meshes are changed only. At the start, this is done:

    mesh = GetComponent<MeshFilter> ().mesh;

    To cache it. So it's not called every frame. Only once per loaded/ new world.

    Then I do:

    mesh.Clear();
    mesh.vertices = newVertices.ToArray();

    However, I have a feeling it could just be that the update chunk function I'm using is unoptimized. Basically, it's a one hundred line function that uses a very basic form of checking if a chunk is updated, then based on that chunk's position, it updates the corresponding chunks. This is very important mostly to have light propagate around corners and show the update to the user. I use to have an older version of this that just checked where the block position was and then updated any neighboring chunks if the faces of the edited area was visible. This ran very fast, but light didn't update to neighboring chunks, especially when placed near the boundaries.

    But I may be using a very naive way of doing this. Cause I'm using a check to see what part of the chunk the light source was just placed, then set a enum flag for where it was, then I use a switch within ifs for each case. Example: if it's in the front z+ part of the chunk, then check to see if it's in the left/ middle/ right (which is all notified by their coordinates within the chunks, then breaking down till it finds the zone, with each zone having a specific set of chunks to update.

    If anyone has a more convenient way of dealing with this problem that can increase performance, I'd like to hear it.
     
  6. CorWilson

    CorWilson

    Joined:
    Oct 3, 2012
    Posts:
    47
    No, I was wrong. The function I use is in fact super fast after doing some tests. So it's mainly more the frequency of updates along with the number of them that happens due to player immediately updating a mesh (this is without light generation), then the second pass being a light update to the surrounding chunks. The water acts on its own thread and does its own updating of chunks, but it has its chunk updates go through the same queue as the light pass. I guess the hardware I'm working on just doesn't like a mesh being dynamically made in runtime, at least at the speed I want it to.

    On PC, obviously, there's no lag at all.
     
  7. codeman_nz

    codeman_nz

    Joined:
    Jul 30, 2015
    Posts:
    11
    Thank you! That's fixed my issue and my game is running smoothly.
     
  8. Duende

    Duende

    Joined:
    Oct 11, 2014
    Posts:
    29
    Hey, amaizing thread!

    When you're adding to the meshFilter.mesh the triangles, vertices and uvs, there is a better way to do this than with toArray()? This method left junk to the GC.
     
  9. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
    I don't think you can avoid it for triangles. For vertices, normals and uvs you could pre-allocate arrays of the largest size you need (potentially use the maximum mesh vertex count) and just assign those to the mesh (any vertices not referenced by index in the triangle array are just unused).
    That said, before any such optimization I'd investigate whether the GC allocation is going to cause any issues. Some GC alloc is fine, as long as it's done infrequently (which, presumably, is the case if the chunks are only updated when blocks are removed or placed).
     
  10. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    402
  11. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
  12. Duende

    Duende

    Joined:
    Oct 11, 2014
    Posts:
    29
    Thanks to both.

    Another question. How do I get shadows in a big scene? I have the Clipping Planes Far of the camera to 100000, because it is a very big scene.

    In quality, if I increase the Shadows Distance, shadows projected in the distance, but the shadows of near disappear.

    I need this for times when the sun rises behind a mountain, for example. The shadow of the mountain should darken the entire valley. If I leave Shadows Distance 200, light in the distance is seen and only obscures the valley around the character at a distance of 200. If I add more Shadows Distance, when the sun rises and light up the valley, the shadows of object closely, disappear.
     
    Last edited: Apr 10, 2016
  13. King-Kadelfek

    King-Kadelfek

    Joined:
    Mar 8, 2010
    Posts:
    15
    I'm a long time reader, but I think it's my first post in this thread.
    I get lot of useful information thanks to you guys, so here is what I did with that.

    Initially, my project was a Minecraft clone with autonomous builders, on both big scale and small scale (nanomachines):

    [​IMG]

    [​IMG]

    Everybody was asking for a way to control the robot cubes, so I created an Artificial Intelligence language made of graphical symbols:

    [​IMG]

    Then I decided to make a whole game (a Programming Puzzle Game) about specific tasks you can perform with the robot cubes:

    [​IMG]
    in each level, you must collect little yellow cubes and reach the exit by writing an AI (top right)

    Later levels in the game will be about building large scale super structures. This one is a stress test (ingame level structures will be smaller) using one million nanomachines to build a 100x100x100 giant cube:

    [​IMG]

    On a technical point of view, my voxel generation is inspired by the most simple tutorials. I usually end up with 500 draw calls (a normal level) to 2 500 draw calls (the galaxy map with all levels), despite having only one material. It's not a problem for computers (I'm running everything on my 2006 Windows XP), but for a later console or mobile port, that would cause a lot of problems.

    When the project will be more advanced, I will upgrade to Unity 5 and redo this part entirely, I hope with help from this thread. :)
     
    Zuntatos, Shinyclef and Farelle like this.
  14. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    483
    Look fun! I assume those rolling cubes are seperate gameobjects and get replaced by a new block of the mesh chunk when they reach their destination?
     
  15. King-Kadelfek

    King-Kadelfek

    Joined:
    Mar 8, 2010
    Posts:
    15
    Exactly. The chunk generation itself is very simple, with 16x16x16 blocks. I'm using a chunk for opaque tiles and another one for transparent tiles. Each chunk have multiple layers (tile, tile over, life), even though I'm not using all of this in the current puzzle game.

    In order to differentiate the art from other voxel games, I put a lot of work on procedural textures.
    Here is a before and after:

    [​IMG]

    It involves 2D raytracing to detect the external edges, 3D scans to detect internal edges. Then I'm painting edges with procedural textures and tilesets, and it slowly appears by glowing with a blending shader. The blue glow is made with a camera screenshot, a custom external blur (with horizontal and vertical passes) and finally a wave distortion shader to achieve the "cosmo" effect.

    [​IMG]

    And here is an old screenshot showing how the glow is done ingame:

    [​IMG]

    I'm taking advantage of the fact you never rotate the level.
    I still need to get some artist involvement to make something a bit prettier, but the basic purpose of having something visually different is achieved, I think.
     
  16. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    1,679
    Hi,
    Hi, your language looks very interesting!

    Just thought I'd throw out, that with some very simple rules you can make your game Turing Complete.

    Some ways would be:

    1. The cube has a direction of movement. If it goes over a black square it turns 90 degrees clockwise and colours the square beneath it white and then moves forward. If it goes over a white square it turns 90 degrees anti-clockwise and colours the square beneath it black then moves forward. ("Langton's Ant"). This is thought to be Turing complete in that by colouring the squares on a grid in a certain way any calculation can be performed.

    2. The cube could detect the 3x3 adjacent squares beneath it. Depending on the colours of these squares black/white it colours them a different colour and then moves in one of the 4 directions. One can make this Turing complete for a certain set of these rules. Kind of like a 2x2 Turing machine except all states are stored in the environment. This one is more based on Wolfram's cellular automata rules.

    3. Similar to the above but with more colours. You can see how certain rules could solve a maze by colouring in the path behind it. But with more colours it is easier.

    Both these methods don't require any internal states. Kind of fun to have a simple game Turing Complete, though not sure how useful it would actually be!
     
  17. King-Kadelfek

    King-Kadelfek

    Joined:
    Mar 8, 2010
    Posts:
    15
    I never thought about using terrain to store data. I was thinking about some levels with color detection, but having color modification could open the path to many uses.

    Besides, as you say it, it doesn't require an internal state. I intend to have internal "variable cubes" with "reader" and "write" instructions, but using the terrain could be a first step.
    One of my intentions is to create some kind of "physical computer made of stone", so I'm interested by any way of replacing computer calculations by moving cubes (i.e. replacing a clock by a cube walking in circles over a pressure plate).

    [​IMG]

    If you have other ideas inspired by the early days of mechanical computations, I'm really interested. :)
     
  18. burli

    burli

    Joined:
    Sep 7, 2016
    Posts:
    15
    Hi, I'm new to Unity, but I want to jump in with another Minecraft Clone. I played and developled mods for another MC clone, but the limitations of the system stopped my enthusiasm. I have tons of ideas I can't accomplish.

    I looked around and decided to start my own project based on Unity and C#. I have quite a lot experience with voxel games, map generation and so on, but unityExperience = null ;-). Well, not null. I have a theoretical idea how it works, but no practical experience yet.

    In contrast to the other MC clones I found here until now I want to split my project into a client and a server. The server shouldn't be developed in Unity. It should be a independent c# console project.

    I didn't read the entire thread, so I'm sorry if I missed something. I didn't found a project, that implements more than basic gameplay with landmass generation. I didn't found a project that adds more blocks like stairs, slabs or other things or even a crafting system.

    I will learn a bit more about Unity and then I will start. Any kind of help is welcome
     
  19. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    5,779

    You can developer a Unity Server or Headless version of your game or app that can work as a server, Unity's Unet networking system is developing this capability. Not sure of current status though.
     
  20. burli

    burli

    Joined:
    Sep 7, 2016
    Posts:
    15
    I know that Unity has Multiplayer support. But I don't want to use this. Don't know if there is another project

    I don't want to focus on mobile platforms. The game should mostly run on PCs. I want to use Unity mostly as graphic engine and not so much as full featured game engine.
     
  21. EuanHollidge

    EuanHollidge

    Joined:
    Nov 3, 2014
    Posts:
    31
    Hey, I know this is an old thread but here is my code that I posted recently. I hope it helps people :) Link
     
  22. burli

    burli

    Joined:
    Sep 7, 2016
    Posts:
    15
    You should remove Start() and Update() if you don't use them like in the Block class
     
  23. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    769
    I started up a new voxel project just for fun (previously had worked on Infichunk earlier in this thread). I wanted to do it differently this time to make things a bit easier. Chunks and blocks are stored a bit differently and I'm using an enum flag system to find blocks and when generating mesh to decide which sides should be generated.

    Here's a few of the scripts I used
    Direction.cs
    VectorI.cs
    MathHelper.cs
    World.cs, ChunkObject.cs, Chunk.cs and Block.cs


    ---
    World
    GameObject _chunkObjectPrefab //The original chunk object to instantiate from
    Queue<ChunkObject> _chunkPool //It's best to pool lots of chunks beforehand
    Dictionary<VectorI3, ChunkObject> _activeChunks; //Store the active chunks in this dictionary based on their position. Their position is located in their bottom left back corner and is always a vector integer.

    ChunkObject //The prefab/original GameObject with this component on it should also already have the MeshFilter, MeshRenderer and MeshCollider components already attached and linked to the variables in this script
    Mesh _chunkMesh
    MeshFilter _chunkMeshFilter
    MeshRenderer _chunkRenderer
    MeshCollider _chunkCollider
    Chunk ChunkData { get; set; }
    World InWorld { get; set; }

    Chunk

    Block[] _blocks
    VectorI3 _size
    VectorI3 Position { get; set; }

    Block
    byte _id
    ---

    And that enum flag system I was talking about... well... it's pretty epic in my opinion.
    Code (csharp):
    1.  
    2. [Flags]
    3. public enum CubeDirectionFlag {
    4.   None = 0,
    5.   LeftDownBack = 1 << 1,
    6.   DownBack = 1 << 2,
    7.   RightDownBack = 1 << 3,
    8.   LeftBack = 1 << 4,
    9.   Back = 1 << 5,
    10.   RightBack = 1 << 6,
    11.   LeftUpBack = 1 << 7,
    12.   UpBack = 1 << 8,
    13.   RightUpBack = 1 << 9,
    14.   LeftDown = 1 << 10,
    15.   Down = 1 << 11,
    16.   RightDown = 1 << 12,
    17.   Left = 1 << 13,
    18.   Right = 1 << 14,
    19.   LeftUp = 1 << 15,
    20.   Up = 1 << 16,
    21.   RightUp = 1 << 17,
    22.   LeftDownForward = 1 << 18,
    23.   DownForward = 1 << 19,
    24.   RightDownForward = 1 << 20,
    25.   LeftForward = 1 << 21,
    26.   Forward = 1 << 22,
    27.   RightForward = 1 << 23,
    28.   LeftUpForward = 1 << 24,
    29.   UpForward = 1 << 25,
    30.   RightUpForward = 1 << 26,
    31.  
    32.   All = 134217726,
    33.  
    34.   Edges = DownBack | LeftBack | RightBack | UpBack | DownForward | LeftForward | RightForward | UpForward,
    35.   Corners = LeftDownBack | RightDownBack | LeftUpBack | RightUpBack | LeftDownForward | RightDownForward | LeftUpForward | RightUpForward,
    36.   EdgesAndCorners = Edges | Corners,
    37.   Faces = Left | Right | Down | Up | Back | Forward
    38. }
    39.  
    40. //You do have to do a bit of weird stuff within a 'for' loop in to check which flags have been set but it's totally worth it (hopefully).. for example
    41.  
    42. public List<BlockNeighbor> GetBlockNeighbors(int index, CubeDirectionFlag directions) {
    43.   List<BlockNeighbor> blocks = new List<BlockNeighbor>();
    44.  
    45.   for(int i = 0; i < 26; i++)
    46.   if(((int)directions & (1 << (i + 1))) != 0) {
    47.   var newDirection = i.ToCubeDirection();
    48.   var block = GetBlockNeighbor(index, newDirection);
    49.  
    50.   blocks.Add(new BlockNeighbor(block, newDirection));
    51.   }
    52.  
    53.   return blocks;
    54.   }
    55.  
    ---

    Annnnd now finally... for the progress so far! A 9x2x9 world with 16x16x16 chunks!
    Average Time = 15.65432ms
    Longest Time = 59ms
    Shortest Time = 7ms
    [​IMG] [​IMG]
    [​IMG]
     
    Last edited: Oct 5, 2016
    MD_Reptile and Jamster like this.
  24. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    1,659
    Hi. I am still having interest in this.

    Making 3d block open world in unity engine is good think? or not? Are there technical hazard or traps?
     
  25. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    1,659
    Hi.
    I am interested. How do you made cube building? like pickaxe building cube? How design its blueprint? Can it be controlled by end user?
     
  26. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    1,679
    I had a good idea for a texel-like game. Imagine when you zoom into each cube, you find it is made up of 16x16 smaller cubes and so on to infinity. My new game I'm working on does something similar but not with cubes. (I should have used cubes!)
     
  27. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    549
    How would you do it? octrees?
     
  28. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
    I'm not sure I agree. Sounds like potentially massive storage requirements, and also sounds like a pain in the ass to mesh properly and efficiently.
     
  29. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    2,409
    There is a game that does it already




    also spore but not as seamless :p
     
  30. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,809
    I'm not really seeing any evidence of voxel anything there, though. Probably just some fancy scene switching stuff, similar concept as in a space sim when you go from planet surface to space.
     
  31. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    2,409
    Okay, let's talk technical :cool:, in general you don't store everything in minecraft too, minecraft generate on the fly using a radius around the player, the same principle can be applied to a forth dimension: scale. Because in the end it was always fancy scene switching, that's how you get infinite world, expect no scene are stored they are generated, and in everything, they are generated procedurally.

    Now the catch is modification, well you only need the delta between the generated seed and the modification to store, that's like order of magnitude less data to store in any case.
     
  32. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    1,679
    I've been making something like that, but with having seamless transitions. (Anyway, I've said too much!) Also, I started making it before I saw the trailer above but I think its a bit different.

    I think I will just give up and bake cookies for a living. :(
     
    Last edited: Dec 31, 2016
  33. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    1,659
    What's the game point at that Everything game? Just get inside to object and then what? just moving? Can it be fun in the end?
     
  34. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    1,679
    I don't think they've figured that out yet! Looks like the plan is: First- get on PlayStation, Second - decide what the point of the game is! They should learn from NMS that if your game doesn't have a good purpose people will trash it. I wish them well, but not too well because my games pretty similar and I don't want the competition! ;) (Although mine has dinosaurs). Fortunately you can't copyright "everything" so there may be lots of similar type of games coming out in the next few years.
    Also, in terms of how I'm making mine, without giving too much away at this point, it uses my own hierachical LOD system along with a method of subdividing meshes fractally. And some algorithms to climb on animals like as in The Last Guardian. I'm only going to store the places where you make a change to the world. And perhaps the movements of creatures you've seen. Probably never get it finished. But its fun to try!
     
    Last edited: Jan 1, 2017
    neoshaman likes this.
  35. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    769
  36. RuinsOfFeyrin

    RuinsOfFeyrin

    Joined:
    Feb 22, 2014
    Posts:
    281
    I was just wondering if anyone besides me was still actively working on their voxel stuff. Good to see!
     
  37. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    483
    A long time ago, I started modifying a very simple voxel engine script I found online to first support things like different block heights (as in, every block's ceiling and floor can start at any height) to more advanced stuff like support for any kind of mesh instead of just using six quads. Over the years, this has mutated into something I no longer call a voxel engine but rather a "Cell Engine". It is basically an editor like those for 2d top-down or isometric games, but in 3d. Instead of tiles, we have cells, and instead of tile graphics, we have meshes. These can also be assigned a texture atlas and recently I even added an uv editor.

    This is an older example of what the engine can be used for:
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    All models and textures where created by me. Veterans of course will recognize that this is Syndicate in 3D, with the buildings of the first map assembled. This actually shows an older version where each cell mesh was unique. Nowadays I can assign a different mesh for each of the six sides.

    I was never interested too much in procedural terrain generation but what I like are level editors which can be used by players to create their own worlds to play in, and my Cell Engine is exactly that. I currently plan to use it for virtually all my future gaming projects as I focus on retro-style games with low-poly models and textures, which is perfect for this system.
     
    Zimbres, Zaelot, GibTreaty and 3 others like this.
  38. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    769
    Originally, I had started my new voxel generator to try and make a map system sort of like Timesplitters Future Perfect (it was like a tiled version of Doom's Snapmap). I wanted to be able to place room pieces next to each other and have the walls appear/disappear/change based on the voxels near them. Each side of the voxel being a wall of a room. It was a fun idea to play around with but I ended up going back on the minecraft-like route again. I added in AABB collision which is a new thing for me to learn. Also added in build-to functionality so when you click to place a block, it'll build a whole line of blocks to reach you. Got that idea from FortressCraft Evolved.
     
  39. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    402
    Oh wow, those visuals remind me so much of roller coaster tycoon 2's theme building system. Except this is full 3d :)
     
  40. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    Hi all!
    I released the new version.

    I came up with a new lighting system.
    Now, I do not store lighting for the map. I compute lighting for column of chunks and and immediately bake it in mesh.
    As a result, memory consumption was reduced. But there are also a problems. I can not get the value of light at any time. It's problem for the dynamic objects and plant\tree generators.
     
    mgear and GibTreaty like this.
  41. Zimbres

    Zimbres

    Joined:
    Nov 17, 2014
    Posts:
    46
    Cherno, I loved your cell-based work. Do you have a blog, or anything to know more about your work?
     
  42. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    483
    Hello and thanks.

    I have no blog, in the past when I started a project I created a development thread on an appropriate forum (for example, my Hired Guns and Hunter remakes on hte English Amiga Board), but since then I stepped away from announcing projects prematurely. Instead, I try to only post something when I have substantial progress on hand. Of course, this could mean that some projects will never be announced in earnest because I tend to work on many different things at once, seemingly abandoning ideas for months or even years whenever something else captures my imagination. My last project was Hired Guns which is pretty advanded right now but since then I have become interested in 2D top-down and isometric tile-based pixel art games. The good thing is that most of game systems I create share some code with the cell engine shown above.

    I still would love to create an isometric fully 3d game set in Syndicate's dark cityscapes but featuring roleplaying elements like buildings you can enter and vendors where you can buy stuff. I still have all the textures and mehses from the screenshots and I hope that I'll get the chance to work more on it.

    So, tl;dr: For advanced projects I will probably have their own development thread here on the Unity Forums, others might only be found in forums dedicated to their scenario.

    Here are some threads:
    https://forum.unity3d.com/threads/my-cyberpunk-rpg-project-top-down-fallout-3-dreamweb.342741/
    http://eab.abime.net/showthread.php?t=68014
    http://eab.abime.net/showthread.php?t=76593
    http://www.yog-sothoth.com/topic/27110-demoniak/