I just have a couple questions before posting the finalized game. I am using a python script to do everything. So…
How do I parent an object to a second object when playing the game? I used the makeParent() function, but it doesn’t parent while the game is going. I need to use python. Would I use setObject() instead?
How can I play an IPO curve for a specific object in python? OR How can I run an actuator (on a different object than the one running the python script)?
I believe that is it… the first question is more important though.
Oh, and the setParent method makes blender close. Here is my code.
#The color face location for the previously activated finger trick
for ob in sce.getObjectList():
if (ob.getName() == color):
faceob = ob
facecolor_loc = ob.getPosition()
facecolor_loc[0] = round(facecolor_loc[0],0)
facecolor_loc[1] = round(facecolor_loc[1],0)
facecolor_loc[2] = round(facecolor_loc[2],0)
#Parent touching blocks (once face has been found)
print 'Parent to ',faceob.getName()
for ob in sce.getObjectList():
name = ob.getName()
block = ob.getPosition()
block[0] = round(block[0],0)
block[1] = round(block[1],0)
block[2] = round(block[2],0)
distance = pow(pow((block[0]-facecolor_loc[0]),2) + pow((block[1]-facecolor_loc[1]),2) + pow((block[2]-facecolor_loc[2]),2),.5)
if (len(ob.getName()) == 5):
distance -= .5
if (distance < 1.1) and (name != 'OBrotation_z') and (name != 'OBArmature') and (name != 'OBred') and (name != 'OByellow') and (name != 'OBwhite') and (name != 'OBgreen') and (name != 'OBblue') and (name != 'OBorange'):
faceob.setParent(ob)
#Run IPO actuator
cont = GameLogic.getCurrentController()
oblist = GameLogic.getCurrentScene().getObjectList()
empty = oblist['OBEmpty']
for ob in oblist:
if ob.name[:6] == 'OBCube' ### OBCube.017[:6] == OBCube
block = ob
blockx = block.getPosition()[0] # [0] is x position of block, [1] would be y and [2] would be z
if blockx > 1: #shoudl find all cubes on the +x side of the rubik's cube
block.parent = empty
#block.parent=object is the same as block.setParent(object)
spinrightside = cont.getActuator('Turn')
GameLogic.addActiveActuator(spinrightside,1) #the 1 means activate
Thanks for the code. My code would be that simple, but I’m making the user inteface a little nicer.
Everything works now except the parenting thing:
I use faceob.setParent(ob) and blender just closes. Yes, it just disappears. No error messages.
Then I switched it to faceob.parent = ob (the only thing I change) and it comes up with the error message “Attribute error: attribute mass is read only” and “Use setParent()”. But of course, if I switch it back, it just crashes. I don’t think the Use setParent() was an actual error message, is it just recommending that? It still doesn’t make the parent though.
So if I wanted to run an actuator on a different object, I would have to switch controller it is referencing to, right?
cont = GameLogic.getCurrentController()
would be…? I don’t know how to get another objects controller.
Finding other object’s controllers is not convenient. You might be able to define controllers to GameLogic.properties from the controller itself and then rotate them. (GameLogic.redfacecont = Gamelogic.getCurrentController, and then from a different object try to manipulate GameLogic.redfacecont)
Or, you may want to try sending messages to the desired object and then have it turn upon receiving a message.
EDIT
I made a rubik’s cube rotate sides at random!
Colours aren’t added yet, and it has no input, but it entertains me