playMaker

Author Topic: Minecraft Chunk Generate  (Read 3528 times)

PikabobAlex

  • Playmaker Newbie
  • *
  • Posts: 22
Minecraft Chunk Generate
« on: December 28, 2012, 11:12:52 PM »
How do I generate a chunk like Minecraft? Can PM make it? How?

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Minecraft Chunk Generate
« Reply #1 on: December 29, 2012, 08:23:25 AM »
I have tried it once, but it is very difficult to optimize it. Generally you'd want to use a nested array. But since that is even with ArrayMaker hard to manage in PlayMaker, you can also do it with cubes.
Create a plane of cubes, let's say 10 by 10. Have them all have a box collider.

To dig:
STATE 1:

On mouse button down;
Mouse pick: hit Object = latestCollider;
Raycast : gameObject = latest collider, direction = 0/0/1 , hitObject = neighbouringBox, distance = 1.5 (anything higher than the extends of the cube itself)
gameObject Is Null : True Event = TRUE, False Event = FALSE;

TRUE goes to STATE2, FALSE goes to STATE3

STATE2
Get Position : gameObject = latestCollider, Vector3 = position;
Vector add XYZ (depending on the direction add some values so the new gameOBject would be a neighbour of the one you pressed on.)
create gameObject : gameObject = Cube, position = position;
 
FINISHED to STATE3

STATE3
Raycast : gameObject = latest collider, direction = 0/0/-1 , hitObject = neighbouringBox, distance = 1.5 (anything higher than the extends of the cube itself)
gameObject Is Null : True Event = TRUE, False Event = FALSE;

STATE3 is like state one without the mouse pick and with a different direction value. You want to cast a ray on each axis to see if there are any neighbours, if there are you do nothing, if there aren't you create them. In the end you can destroy the gameObject you clicked on.

Now, this is all nice and dandy, but it does not help yet, since if we click somewhere , there will be a block on top of the hole we just created too. So we need to introduce exceptions. I did them on the basis of the position of the blocks. For each cube I destroyed ,I would add the world position to an array list component on my camera. Then each time I would create a cube (eg STATE2) I tested if the position and if it existed already, I would skip the creation because this means that I've made a hole their before, and don't want it to be autofilled.
So on start I run a script that takes every gameObject there and adds their position + 1 on the y axis to the list. That way everything on top of them is treated as if I destroyed cubes there. You can do it multiple levels high and then define a max height for the user to build.

For performance issues you need to implement patches (like those 10x10 we just created) and make tem interact with each other. That way they will not have to test an infititely long list to see if a vector3 has ever been emptied.
Also you may consider combining cubes farther away to one mesh to save resources. Unity handles a lot of small objects badly.

In the attachments I added an early build of my own minecraft version, though I made some mistakes there which I didn't put in my explanation, so it may be slower than your version of it.
Hope it helped ;)
Best,
Sven

PikabobAlex

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Minecraft Chunk Generate
« Reply #2 on: December 31, 2012, 12:54:32 PM »
I saw on youtube , they are using the Noise to generate the Map...
Very amazing...