- Home /
Multiple part / project / general advice question.
How to create a simple world generator in Unity3D?
Hello!
I'm creating a survival game, like minecraft, but instead of blocks, I have some simpler geometry, somehow similar to the geometry style in The Long Dark or Unturned. I'm going to create a simple world generator, but I don't really know how I can do it, so I have some questions:
Creating and Saving
Can I create a new empty Scene from a C# script?
(If above is possible) Can I start to populate the new Scene, from a C# script?
(If above is possible) Can I serialize/save everything in the Scene, or just save the Scene as a .unity file, from a C# script?
Generation
I have thought of two ways of doing the generation. Either generate a Terrain
, or to create a new flat (plane) Mesh
and use the Diamond Square Algorithm to place some vertecies with random heights on it, to create a simpler terrain. I think the last one siuts best to the rest of my game's "geometry style", so thats the one that I want most, if it's possible, but I don't know (if I can) how I can do that from a C# script in unity.
I also want to populate it with some trees, bushes, entities, structures etc. but I have an idea of how I can do that. I will just simply cast some raycast, and check if they hit the ground, and if they do, I'll randomly (with some kind of seeding) select one object and place it where the hit occurred. In that way, I can decide how many objects I want, by changeing the number of casted raycasts. I can also extend it so that I can controll how many of each object that will be spawned.
Conclusion
I want to, from a C# script, create a new Scene, generate a new flat mesh and use the Diamond Square Algorithm to place vertecies with random heights on it, so that it looks like a terrain, something like this, which demonstrates the Diamond Square Algorithm, and start to populate it with structures, foilage, entities etc. Lastly, I, also from a C# script, want to serialize/save the Scene, or all objects in the Scene, to a file.
All help is greatly appreciated!
// TheDDestroyer12
I think this is more a project than a question and too big for this forum.
$$anonymous$$aybe you are better off asking someone in person or getting a mentor/course for this. This would be a very lengthy solution, it's also multiple questions in 1. This answer wiki is more concise
Answer by GameVortex · Jan 06, 2015 at 09:22 AM
You have a really well put together post and the project sounds interesting. But with no proper question this post would be a lot better suited on the forums as Unity Answers is for specific technical questions.
One place to start is to search around for Unity World Generation. There are a lot of people that have done something similar, and there might even be some plugins on the Asset Store that can help you greatly.
Good luck on your project.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Percentage based chance in C#? 2 Answers
Distribute terrain in zones 3 Answers
World Spawn Layer under current Layer 1 Answer
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer