I’m building a model of a wind-up toy. Nothing too complicated, just a spinning axle with two “Arms” at each end. When the arms hit the ground they lift the rest of the model up and forward. The whole procedure is done with physics, no animation.
The whole thing worked wonderfully until I tried to instance the group. Apparently “rigid body constraints” do not persist into instances. So I created an initialization script and set up the constraints via code. That’s when the second problem reared its ugly head. See, the arms need to have all rotation disabled. If I use setParam() to disable the Y and Z axis, no problem, but if I try to use it on the X (incidentally, the same axis the axle rotates on) the whole model disappears.
I tried tracking the model, but its given position is [inf., inf., inf.]. Switching constraint types had no effect. Below is a copy of the model before I switched to Python:
Spin Wukong.blend (508 KB)
and after,
Spin Wukong2.blend (509 KB)
If you don’t feel like downloading, here’s a copy of the code I use to initialize the model:
#Initialize the variables
controller = bge.logic.getCurrentController()
owner = controller.owner
initialize = controller.sensors["Initialize"]
begin = controller.actuators["Begin"]
scene = bge.logic.getCurrentScene()
#Get the objects
owner["Wukong"] = scene.objects["Wukong-bot"]
owner["Axle"] = scene.objects["Axle"]
owner["Left"] = scene.objects["Shaft.L"]
owner["Right"] = scene.objects["Shaft.R"]
if initialize.positive:
#Set the constraints
axleConstraint = bge.constraints.createConstraint(owner["Axle"].getPhysicsId(), owner["Wukong"].getPhysicsId(), bge.constraints.CONETWIST_CONSTRAINT, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
rightArmConstraint = bge.constraints.createConstraint(owner["Right"].getPhysicsId(), owner["Axle"].getPhysicsId(), bge.constraints.CONETWIST_CONSTRAINT, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0)
leftArmConstraint = bge.constraints.createConstraint(owner["Left"].getPhysicsId(), owner["Axle"].getPhysicsId(), bge.constraints.CONETWIST_CONSTRAINT, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0)
#Create Parameters
#rightArmConstraint.setParam(3, 0.0, 0.0)
rightArmConstraint.setParam(4, 0.0, 0.0)
rightArmConstraint.setParam(5, 0.0, 0.0)
#leftArmConstraint.setParam(3, 0.0, 0.0)
leftArmConstraint.setParam(4, 0.0, 0.0)
leftArmConstraint.setParam(5, 0.0, 0.0)
print(owner["Right"].localPosition)
#Start the axle turning
owner["Axle"].sendMessage("turn")
#controller.activate(begin)
Any insight you can offer would be much appreciated.