use ray .hit position . build on a local grid,

So, basically what I need is like the minecraft block placing by many people here, but I need the grid local to the object hit,

second off, I need the pieces to align correctly.

this will simplify my vastly over complicated assembly system


here is a .blend I started trying to solve the problem but I am tired for tonight


import bge
from mathutils import Vector


def main():


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


    sens = cont.sensors['Ray']
    sens2 = cont.sensors['Keyboard']
    sens3 = cont.sensors['Property']
    


    if sens.positive and sens2.positive and sens3.positive:
        vex= Vector(sens.hitPosition)
        offset=(vex-sens.hitObject.worldPosition)*sens.hitObject.worldOrientation
        print(str(offset))
        target=sens.hitObject
        if offset.x>0:
            LR=2
        else:
            LR=-2
        if offset.x==0:
            LR=0    
        if offset.y>0:
            FB=2
        else:
            FB=-2
        if offset.y==0:
            FB=0       
        if offset.z>0:
            UD=2
        else:
            UD=-2
        if offset.z==0:
            UD=0       
        own.worldPosition=target.worldPosition
        own.worldOrientation=target.worldOrientation
        own.applyMovement((LR,FB,UD),1)
        own['prop']=True                    
                
    


main()



Attachments

Sleepyattempt.blend (437 KB)

ok looks like I got it!

Let me know if you see anything I did wrong or that needs improvement, please
:smiley:


import bge
from mathutils import Vector


def main():


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


    sens = cont.sensors['Ray']
    sens2 = cont.sensors['Keyboard']
    sens3 = cont.sensors['Property']
    


    if sens.positive and sens2.positive and sens3.positive:
        vex= Vector(sens.hitPosition)
        vex=vex*sens.hitObject.worldOrientation
        offset=(vex)-(sens.hitObject.worldPosition*sens.hitObject.worldOrientation)
        print(str(offset))
        target=sens.hitObject
        if offset.x>.5:
            LR=2
        else:    
            if offset.x<-.5:
                LR=-2
            else:
                LR=0    
        
        if offset.y>.5:
            FB=2
        else:    
            if offset.y<-.5:
                FB=-2
            else:
                FB=0    
        
        if offset.z>.5:
            UD=2
        else:    
            if offset.z<-.5:
                UD=-2
            else:
                UD=0    
        print(str(LR)+" "+str(FB)+" "+str(UD))
        own.setParent(sens.hitObject,0,0) 
        own.worldPosition=target.worldPosition
        own.worldOrientation=target.worldOrientation
        own.applyMovement((LR,FB,UD),1)
        own['prop']=True
                            
                
    


main()



Attachments

localGrid.blend (438 KB)

So this turns out a dead end, the “Tmesh_flags” I was using in my old system, followed the transforms of the “host component” so, when the objects became compound, the Tmesh flag still allowed the selection of the components,

in a standard compound, if I raycast and hit it, I don’t get the ID of the child,

in component

delay(fire one time only)--------------add Tmesh flag - property ‘Component’ = spawning item

then raycasting and hitting the flag

sens.hitObject[‘Component’] = the object that spawned the component,

currently each component is managing itself, this is not as efficient as a single script running a list,


for Tmesh in Tmesh_List:
    Tmesh.worldPosition=Tmesh['Component'].worldPosition
    Tmesh.worldOrientation=Tmesh['Component'].worldOrientation

Edit :

Tmesh = Triangle mesh “Jack Map” using materials