3D building system!

Hi! I wanted to find out how to make a 3D building system(like in Minecraft or other survival games). I have found a lot of tutorials for 2D building, but none for 3D. Please, make some tutorials and example .blends for me:)

OK! But I would like to know how to make it. Actually, I would like to get something like this: https://www.youtube.com/watch?v=q0vtA7XOdb0 Unfourtunately, there aren’t any tutorials or downloads of this. Anyway, the minecraft and the other prot-minecraft works fine. I just want to find out how to add object according to position of mouse(in voxel tiling).

Hey that’s my video lol

Well, Than you could post a tutorial, right?:smiley:

I suppose I could

I have discovered the system of building, but the problem is to make sure so object gets added on the side of object if I aim on side of it, not on top of it…

there’s a little trick I came up with solve that

Have you looked up hitNormal?
It tells you what direction the face you aim at is facing towards.

thats the ticket

so basically, back of cube is - (0, -1, 0) , front - (0, 1, 0), left - (-1, 0, 0), right - (1, 0, 0) bottom - (0, 0, -1), top - (0, 0, 1)

if you had a placeholder (a plane invisible on the ground) you can use its coords/orientation to place a new object.


  if mouseoverany.positive:
      hit = mouseoverany.hitObject
      if "place_holder" in hit: 
          place_holder = hit
          scene.addObject(object_to_add, place_holder, 0) 

you should probably set some property on the placeholder , as “used” True/False

Well I will need very simple example, because I don’t understand yet. I used logic and only script for object to follow mouse

Hello! I don’t know if this is a good technique, but here is a little demo I just made:

I tested your method. Updated it a bit. It looks fine, but… Sometimes the green plane rotates for some reason and blocks don’t get placed stright in 0, 90, 180 and 270 degrees angles. Maybe you know some resolvement. Also, I don’t know how to make it able to place/break blocks only, if player is close enaugh…

You add a marker object even if no mouse click event has happened.


import bge

# block placement and deletion script
def manipulation():
   
    scene = bge.logic.getCurrentScene() 
    cont = bge.logic.getCurrentController()
    own = cont.owner


    sensor          = cont.sensors['over_any']
    left_click      = cont.sensors['left_click']
    right_click     = cont.sensors['right_click']
    hit_object      = sensor.hitObject
    hit_normal      = sensor.hitNormal

    <b>if not "Marker" in own:
            own["Marker"] = scene.addObject("Marker",own)</b>
  <b>  if  hit_object :
            
        NewPosition     = hit_object.worldPosition + (hit_normal)                    
         
        new_block       =  own["Marker"] 
        
        new_block.worldPosition = NewPosition
        new_block.worldOrientation = (0,0,0)  
</b>    else:
        new_block       =  own["Marker"]         
        new_block.worldPosition = [-99999,-9999,-9999]

    if left_click.positive: 
        if  hit_object :
            NewPosition     = hit_object.worldPosition + (hit_normal)
            new_block       = scene.addObject("block",own)
            new_block.worldPosition = NewPosition
            new_block.worldOrientation = (0,0,0)


    elif right_click.positive: 
        if  hit_object : 
            hit_object.endObject()
manipulation()

http://i.imgur.com/bZRAh97.gif
Edit:update

Where and how to apply that script? Should I just update the current script with this and add an object called Marker?

Yes :smiley:
Should be easy

I also want to check if the object is close enaugh- if it isn’t, than it should not be possible to add/destroy block(you cant place block in distance of 10m, can you?). Also, is it possible to make it like this?:

if left_click.positive: 
        if  hit_object :
            if own['blocks'] &gt; 0:
                NewPosition     = hit_object.worldPosition + (hit_normal)
                new_block       = scene.addObject("block",own)
                new_block.worldPosition = NewPosition
                new_block.worldOrientation = (0,0,0)

But to carry 64 cubic meters of dirt/stone is perfectly normal :slight_smile:

As it was meant to be a simple example i didn’t concern myself with trivialites like that, but of course,
several “if” statements are needed for it to be a game. Maybe the most crucial being that you don’t spawn a block in the space you occupy.

Also, yes, sure that would work.

So I can make it like this, right?:

if left_click.positive:
    if own['itemSelected'] == 1
        if own['dirt'] &gt; 0:
            NewPosition = hit_object.worldPosition + (hit_normal)
                new_block = scene.addObject("dirt",own)
                new_block.worldPosition = NewPosition
                new_block.worldOrientation = (0,0,0)
    elif own['itemSelected'] == 2
        if own['log'] &gt; 0"
            NewPosition = hit_object.worldPosition + (hit_normal)
                new_block = scene.addObject("log",own)
                new_block.worldPosition = NewPosition
                new_block.worldOrientation = (0,0,0)