Help me get this working perfect? (Project:Wrectifed) Ray-Block-Placer

Ok—

here is a complex system - Wrectifed

I need help with “Cube.py”

and the “Hold” filter

Open the .blend,
Mouse= aim Ray
Press X - this is “Pick up”
Press P = parent ray

Check it out?
EDIT: POSTED NEW FILE

It needs love

think “mine craft style alignemnet and parenting”

Specifically Cube.py

in the

if value= “Parent”
section

I need help so the cubes “snap” into position, in alignemend with the SIDE OF THE CUBE casting face and the struck face.
as well as be independant of the ray length.
Anyone care to tinker?

Attachments

WrectifiedCurrentALPHA2.blend (4.65 MB)

/\ Bump update /\

I think you should have the object move up until it detects a certain property and then move to the side until it detects a certain property.That is the best i can explain it right now.I am going to try to make it sometime today because i need that to.Another hint have it move fast and then stop.Here is the blend
example.http://www.pasteall.org/blend/22343

3d-solar ____Ok… I a bit am confused, but hey, I don’t always explain myself perfectly either,
Ok so …

COMMUNITY
Please get the .blend

Right now if I do
object.setParent(target,0,0)
1.- the cubes fly off the screen - I think this has to do with physics bounds,
2.- I need help “open locations” ie. The Side of the “Casting face” of the cube, will line up with the side of the Struck cube, on the side where it was struck.

Attachments

WrectifiedCurrentALPHA2.blend (4.65 MB)

Bump - added graphic description


This is what needs to happen, with compound physics

Just align the cube to the face normal and move it to its position.

Take a look at rayCast()
http://www.tutorialsforblender3d.com/GameModule/ClassKX_GameObject_21.html

Ex.

Code it in then? :smiley:

I don’t really understand the math in it :smiley:

This track to alines the blocks.Unless you want it to jump up.You can have it jump up to.Look at the logic bricks in the blend.http://www.pasteall.org/blend/22348

So can I use a point in 3d space as a target of track to?

So Position

Get “hit point”, which side of block is on
Get vector -> diffenance from Center of “struck block” to hitpoint

if difference.x > difference.y and difference.z then side for alignement = side 1

if -difference.x > -difference.y and -difference.z then side for alignement = side 2?

the math is what I am having trouble with…

No you can’t.You can use an empty like i did just place it on the face.

I would do that, but I need to place it on a 3d point anyway, so if I can get the math right… I can just do it with setWorldPosition and setWorldOrientation but my brain is apperantly made of rocks and bits of broken glass. :smiley:

Ok still need help

specifically
this locks it parented, but does not do what I am looking for

Please get the .blend and look over Cube.py

it controls the “Component cubes” in the .blend

Not to much left until I can make a great game

(Thank you KupoMan!!!) LOD was a big piece of the puzzle


 if value == "Parent":
                                if object['Effector']==True:
                                    hitOb[key] = "Empty"
                                    object[polyProperties[item]] = "Empty"
                                    object['hostID'] = 0
                                    object.state = 1
                                    object['Holding']=False
                                if object['Effector']==False:
                                    Rot = object.worldOrientation.copy()
                                    object['Holding']=False
                                    object[polyProperties[item]] = "Empty"
                                    object.worldPosition = hitOb.worldPosition + hitNormal.normalized() * distance
                                    object.alignAxisToVect(hitNormal)
                                    object.setParent(hitOb,0,0)
                                    object['hostID'] = 0
                                    object.state = 1
                                    print(object[polyProperties[item]])
                                    object[polyProperties[item]] = "Empty"
                                    hitOb[key] = "Empty"
                                    object.worldOrientation=Rot

Here is an example using rayCast, maybe you can use something similar in your problem
http://www.pasteall.org/blend/22358

Ex.

It already casts rays, I have the hit poly,just not the math… check the .blend
Its exactly what I need…

My file runs in 2.66a and not 2.67 though… ???

I can hack it in, I need to declare all of these properties some where though

The script is a 3d logic node system, that passes data using polydata to grab indexed list property, and pass it using rays, I am adding in parenting and activating various properties,

<-----wrote about 22% of this python (I have been slowly learning)

Can anyone “Hack it in?”

How can I paste something into a place and have it indented correctly?

Post - whole script


from bge import render, logic 
from mathutils import Vector # for easy editing of Vectors


distance = .225


# the distance of the ray




def castRay(cont):
    
    object = cont.owner
    
    # Create the lists
    objectProps = object.getPropertyNames()
    polyProperties =[]
    polyValues=[]
    polyIndex = []
    #polyRayCastId = [] | I didn't actually use this list
    
    # initiate x to 0
    x = 0 
    
    # Check the objects properties
    for prop in objectProps:
        
        # Look for Properties that have "FaceProperty" in them
        if "FaceProperty" in prop:
            polyValues.append(x)
            polyProperties.append(prop)
            # increment x
            x = x + 1
            #polyRayCastId.append(x) 
        
        # Look for Properties that have "FaceIndex" in them 
        if 'FaceIndex' in prop:
            polyIndex.append(prop)
    
    # if "polyData" is present in the object then this wont run
    if not 'polyData' in object:
        mesh = object.meshes[0]
        CalcMeshData(mesh) # I just moved these calculations to a function so it was easier to read the code
        
    transform = object.worldTransform
    polyData = object['polyData']
    hostID = object['hostID']
    
    # this loops through the indexes we collected earlier   
    for item in polyValues:
        # Check to see if the property needs to send data
        value = object[polyProperties[item]]
        if object[polyProperties[item]] != "Empty" and value != None:
            if value == "Hold":
                if object['Effector']==False:
                    if object['Holding']==True:
                        object['Holding']=False
                        object[polyProperties[item]] = "Empty"
                   
                    if object['Holding']==False:
                        object['Holding']=True
                        object[polyProperties[item]] = "Empty"
            # loops through the mesh data
            for data in polyData:
                id = int(data[0][-2:])
                
                #if the current FaceIndex is equal to the mesh Id then it casts a ray
                if object[polyIndex[item]] == id:
                    start = Vector(transform * data[1])
                    end = Vector(transform * (data[1] + data[2]))
                    render.drawLine(start, end, [0, 255, 0])
                    hitOb, hitPos, hitNormal, hitPoly = object.rayCast(end, start, 0, '', 0, 0, 1)
                    
                    # if the ray hits another object,
                    # it gets the face id and gives it the data
                    if hitOb == None:
                        object[polyProperties[item]] = "Empty"
                        render.drawLine(start, end, [255, 0, 0])
                    if hitPoly:
                        hitMat = hitPoly.material_name
                      
                            
                        if 'Sensor_' in hitMat:
                            hitID = int(hitMat.split("_")[1])                             
                            hitOb['hostID'] = hitID
                            value = object[polyProperties[item]]
                            key = "FaceProperty_{}".format(hitID)
                            
                            if hitID &lt; 10:
                                hitOb["FaceProperty_0%s" % (hitID)] = object[polyProperties[item]]
                                if value !="Parent":
                                    object[polyProperties[item]] = "Empty" 
                            else:
                                hitOb["FaceProperty_%s" % (hitID)] = object[polyProperties[item]]
                                if value !="Parent":
                                    object[polyProperties[item]] = "Empty"                       
                            
                            
                                                      
                            
                            object['hostID'] = 0
                            object.state = 1
                            
                            
                            if value == "Parent":
                                if object['Effector']==True:
                                    hitOb[key] = "Empty"
                                    object[polyProperties[item]] = "Empty"
                                    object['hostID'] = 0
                                    object.state = 1
                                    object['Holding']=False
                                if object['Effector']==False:
                                    Rot = object.worldOrientation.copy()
                                    object['Holding']=False
                                    object[polyProperties[item]] = "Empty"
                                    object.worldPosition = hitOb.worldPosition + hitNormal.normalized() * distance
                                    object.alignAxisToVect(hitNormal)
                                    object.setParent(hitOb,0,0)
                                    object['hostID'] = 0
                                    object.state = 1
                                    print(object[polyProperties[item]])
                                    object[polyProperties[item]] = "Empty"
                                    hitOb[key] = "Empty"
                                    object.worldOrientation=Rot
    object[polyProperties[item]] = "Empty"
    


def CalcMeshData(mesh):
    
    polyData = []
    
    # loops through all the polygons in the mesh
    for polyId in range(mesh.numPolygons):
        poly = mesh.getPolygon(polyId)
        polyMat = poly.material_name
        
        # is the polygons material name cantains "Sensor_"
        if 'Sensor_' in polyMat:
            matID = poly.material_id
            numVerts = poly.getNumVertex()
            coords = Vector((0, 0, 0))
            normalList = []
            totalNormal = Vector([0,0,0])
            
            # Loops through all the vertices in the polygon
            for vertIndex in range(numVerts):
                vert = mesh.getVertex(matID, vertIndex)
                coords += vert.XYZ
                normalList.append(vert.normal)
            
            # adds all the vertex normals together
            for n in normalList:
                totalNormal += n                              
            
            # averages out the normal and applies the distance
            polyNormal = (totalNormal / len(normalList)) * distance
            # averages out the position
            polyPos = coords / numVerts
            
            # adds the data to the list
            polyData.append([polyMat, polyPos, polyNormal])
    
    # assigns the list to a property on the object       
    logic.getCurrentController().owner['polyData'] = polyData

I could use some help. this script http://www.pasteall.org/43548/python

I have in http://www.pasteall.org/blend/22359

I need this integrated in the section
if value== “Parent”

instead of what is there, something like this system
for some reason I can only get cube.py to work in blender 2.66a

http://www.pasteall.org/blend/22358 <- align to normal and then initiate parent

Did you submit your problem to the blender game engine bug tracker on blender.org?

Not yet,
It’s like the rays don’t shut off, or hang up or something.

the file runs, just cube.py does not work the same,

I don’t know exactly where the error lies in the conversion…

Ok posted the bug XD


 if value == "Parent":
                                if object['Effector']==True:
                                    hitOb[key] = "Empty"
                                    object[polyProperties[item]] = "Empty"
                                    object['hostID'] = 0
                                    object.state = 1
                                    object['Holding']=False
                                    
                                if object['Effector']==False:
                                    Rot = object.worldOrientation.copy()        # &lt;&lt; ??(1)
                                    object['Holding']=False
                                    object[polyProperties[item]] = "Empty"      # &lt;&lt; ??(2)
                                    object.worldPosition = hitOb.worldPosition + hitNormal.normalized() * distance
                                    object.alignAxisToVect(hitNormal)           # &lt;&lt; ??(1)
                                    object.setParent(hitOb,0,0)
                                    object['hostID'] = 0
                                    object.state = 1
                                    print(object[polyProperties[item]])
                                    object[polyProperties[item]] = "Empty"      # &lt;&lt; ??(2)
                                    hitOb[key] = "Empty"
                                    object.worldOrientation = Rot               # &lt;&lt; ??(1)
                                    
                                    

what do alignAxisToVect() ?(nothing)
i add a line localPosition after setPArent() .(rahter than worldPosition)
anything sure if it work of course


 if value == "Parent":
.....
    

EDIT:
wait, localPosition is wrong surely :confused:
distance should be something as a the length of the cube…


 if value == "Parent":
                                if object['Effector']==True:
                                    hitOb[key] = "Empty"
                                    object[polyProperties[item]] = "Empty"
                                    object['hostID'] = 0
                                    object.state = 1
                                    object['Holding']=False
                                    
                                if object['Effector']==False:
                                    distance = 2 #??
                                    object['Holding']=False
                                    object.alignAxisToVect(hitNormal) 
                                    object.setParent(hitOb,0,0)
                                    object.worldPosition = hitOb.worldPosition + hitNormal.normalized() * distance
                                    object['hostID'] = 0
                                    object.state = 1
                                    print(object[polyProperties[item]])
                                    object[polyProperties[item]] = "Empty" 
                                    hitOb[key] = "Empty"