Please help me stack cubes

Hi! Can anyone please help me stack and put some cubes beside each cube? Minecraft like where you can put another cube by click at the side of the cube. I was able to add cube on the plain but I can’t put cubes on top of another cube.

Thank you!

property Time—
mouse click--------python
mouse over any—/

python*

from mathutils import vector
import bge

cont = bge.logic.getCurrentController()
own=cont.owner

cam=bge.logic.getCurrentScene().active_camera
MOA = cont.sensors['MouseOverAny']
Click= cont.sensors['Mouse']
Time=cont.sensors['PropertyTime']

objectName='nameOfObjectOnHiddenLayer'

if MOA.positive and Click.positive:
    if 'Time' not in own:
        own['Time']=0
    if own['Time-']==0:
        own['Time']=30
        hitObject=MOA.hitObject
        
        diff = hitObject.worldPosition+(hitObject.worldOrientation*Vector(MOA.hitPosition))
        locations= [Vector([1,0,0]),Vector([-1,0,0])Vector([0,1,0]),Vector([0,-1,0]),Vector([0,0,1]),Vector([-1,0,0])]
        for places in locations:
            diff2=diff-hitObject.worldPosition+(hitObject.worldOrientation*places)
            if diff.magitude<.5:
                added=bge.logic.getCurrentScene().addObject(objectName,own,0)
                added.worldPosition=hitObject.worldPosition+(hitObject.worldOrientation*places)
                added.alignAxisToVect(MOA.hitNormal,1,1)
                added.worldPosition=added.worldPosition+(added.worldOrientation.col[1]*1)

This is incomplete and I will look it over and finish it tommarrow

I will finish this tonight, I did not forget about you.

Done -


from mathutils import Vector
import bge


cont = bge.logic.getCurrentController()
own=cont.owner


cam=bge.logic.getCurrentScene().active_camera
MOA = cont.sensors['MouseOverAny']
Click= cont.sensors['Mouse']
Time=cont.sensors['PropertyTime']


objectName='PlaceCube'
if own['Time']>=1:
    own['Time']-=1
if MOA.positive and Click.positive and not Time.positive:
    
    if own['Time']==0:
        own['Time']=30
        hitObject=MOA.hitObject
        print(hitObject)
        
        diff = MOA.hitObject.worldPosition-MOA.hitPosition
        diff = hitObject.worldOrientation.inverted()*diff
        diff*=1
                   
        locations= [Vector([1,0,0]),Vector([-1,0,0]),Vector([0,1,0]),Vector([0,-1,0]),Vector([0,0,1]),Vector([0,0,-1])]
        for places in locations:
            
            diff2= (hitObject.worldOrientation*places)
            print("hitPoint local is at "+str(diff))
            print(diff2)
            diff2 = diff2-diff
            print(diff2.magnitude)
            if diff2.magnitude<.5:
                print('adding')
                added=bge.logic.getCurrentScene().addObject(objectName,MOA.hitObject,0)
                added.alignAxisToVect(MOA.hitNormal,1,1)
                added.worldPosition=hitObject.worldPosition+(added.worldOrientation.col[1]*2)
                
                
                

Attachments

MineCraftish.blend (503 KB)

You can use the Array Modifier in the “Add Modifiers” Tab.

Thank you so much! Please also check your inbox. Thank you.

in this example I use a property to set which block to place off of the hidden layer 2

No problem, I just figured out this math a little bit ago :smiley:

Attachments

MineCraftish2.blend (560 KB)