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?
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.
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
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.
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?
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 < 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