マインクラフト風の地形

Creating a Minecraft-like landscape and uploading to STYLY -part 1 of 2-

Creating a Minecraft-like landscape and uploading to STYLY -part 1 of 2-

In this article, I will introduce how to create a Minecraft-like landscape and upload it to STYLY.

Minecraft風の地形

Minecraft-like landscape

Confirm sample assets with WebEditor

Confirm sample assets with WebEditor
Launch the WebEditor

* If you  register STYLY, you can check the sample assets created with this TIPS with WebEditor.
If you do not register an account, please register again and click this button again.

Register for account from here
Click here

 

Sample

Open a sample scene from the STYLY GALLERY.
Sample scene

How to create a Minecraft-like landscape

We will create a Minecraft-like landscape using the following 5 steps.

    • Auto-creating a landscape in Unity
    • Pasting textures
    • Combining meshes and improving performance
    • Save auto-created meshes
    • Create a prefab from the saved meshes and uploading

I will explain the 5 steps briefly.

Auto-creating a landscape in Unity

Unityのランダム関数を使って、地形っぽくキューブを配置します。

Use the random number generator and place cubes so they form a landscape.

Pasting textures

高さによって張り付けるテクスチャを変えていきます。

Paste textures to the cubes and change the texture according to the height of the cube.

Combining meshes and improving performance

2500個のキューブ。これをSTYLYにアップロードしても、ビューワが落ちます。

If we upload 2500 cubes to STYLY, the viewer will freeze.

2500個のキューブを結合してできたメッシュ。これならビューワも落ちません。

By combining the meshes of 2500 cubes, the project will not freeze even when uploaded to STYLY.

Save auto-created meshes

生成したメッシュを保存しておきます。

Save the created mesh

Create a prefab from the saved meshes and uploading

作成したメッシュを適当なgameobjectに貼り付け、prefab化します。

Paste the created mesh to a game object, and create a prefab from it.

最後にSTYLYにアップロードすれば完成です。

Uploading to STYLY

Ok, let’s go through the steps in detail.

Auto-creating a landscape in Unity

Preparation

  • Creating a base object

Create a cube to the scene, and name it “Ground”.

Groundオブジェクトの作成

Creating the Ground object

  • Create a ground forming object

Add the following script and name it “VoxelGround.cs”.

Confirm the results

Add “VoxelGround” as a component to Ground object.

「VoxelGround(Script)」を追加

Adding VoxelGround

Press the Ctrl + P keys and if a landscape like the one in the image below gets created, it is a success.

成功

Success

Explanation

  • About VoxelGround.cs
We specify the size of the landscape here.

The sizeW might be hard to understand, but it is the distance from the top of the mountain to the ground.

So, in the sample, a mountain is created from 17 blocks, which means there will be about 3 mountains created from 50 blocks.

If we make the number smaller than 17, there will be more mountains created in the scene.

In the sample, we will create 50 blocks on the X-axis, and 50 blocks on the Z-axis, resulting in 2500 blocks.

By using Mathf.PerlinNoise as the height of the blocks, we can create a smooth landscape.

Pasting textures

Preparation

  • Importing textures

Download a texture pack from a Minecraft fansite.

The texture used in this sample was downloading from the following URL.

detailed minecraft

テクスチャパック

Texture pack

Import the texture to the Unity editor.

テクスチャのインポート

Importing the texture

  • Creating a material

Drag and drop the imported texture to the “Ground” game object.

テクスチャをゲームオブジェクトにドラッグアンドドロップする

Drag and drop the texture to the game object

The texture will be applied to the “Ground” object, and check that a material with the same name as the texture is created.

( In the sample, the material name is “terrain 6.26.56 PM” )

マテリアルが作成される

A material is created

  • Adjusting a ground forming object

Adjust “VoxelGround.cs” as below.

Confirm the result

Press the Ctrl + P keys, and see if a landscape like the one in the next image is created.

地形にテクスチャを適用
Apply textures to the landscape

Explanation

  • About the texture
テクスチャパック
Texture pack

The image above is called a texture pack, and the textures needed to create a minecraft-like landscape is included.

By using a texture pack, we only need one material for the scene, so we are able to combine the meshes.

  • Adjusting the script①
In the sample, the texture is changed according to the height of the landscape.

We set the following:

For GetBlockUVs(0, 15) we set the left top texture of green grass

For GetBlockUVs(15, 0) we set the right bottom texture of red lava

  • Adjusting the script②
In the sample, we set the texture to the cube-shaped meshes.

For pixelSize, we set the row number of the texture pack. In the sample, we are using a 16 x 16 texture pack, so I set the variable as 16.

I referred to the below blog for UV.

”Unity の Cube を使う時、側面の天地が揃う UV 作った”

Conclusion

That will be all for part1.

We have completed the first 2 steps of the whole 5 steps, and we have finished creating the appearance of the landscape.

  • Auto-creating a landscape in Unity
  • Pasting textures
  • Combining meshes and improving performance
  • Save auto-created meshes
  • Create a prefab from the saved meshes and uploading

To upload this project to STYLY, we need to combine and save thousands of cubes, and finish up the settings.

In the latter article, I am going to explain how to do this.

This is not an official product of Minecraft. This product is not approved from Mojang, and is not related to Mojang.