setParam Causing Object to Disappear

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)
#Start the axle turning

Any insight you can offer would be much appreciated.

I have same problem. But isn’t setParam


constraints_what_happen.blend (612 KB)

View My Video


 import bge

def crea1constraint():
	main = "lThigh"
	physicsid = bge.logic.getCurrentScene().objects[main].getPhysicsId()
	target = "Behemoth_62096"
	physicsid2 = bge.logic.getCurrentScene().objects[target].getPhysicsId()
	print("Before create constraint: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)
	test_constraints = bge.constraints.createConstraint(physicsid, physicsid2, bge.constraints.LINEHINGE_CONSTRAINT, 0,0,0,0,0,0)
	print("After create constraint: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)

	print("After set param 1: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)
	print("After set param 2: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)
	print("After set param 3: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)

	print("After set param 3: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)
	print("After set param 4: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)
	print("After set param 5: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)

print("After crea1constraint function: ", bge.logic.getCurrentScene().objects["abdomen"].worldPosition)



Before create constraint:  <Vector (0.0396, 0.2024, 2.3846)>
After create constraint:  <Vector (0.0396, 0.2024, 2.3846)>
After set param 1:  <Vector (0.0396, 0.2024, 2.3846)>
After set param 2:  <Vector (0.0396, 0.2024, 2.3846)>
After set param 3:  <Vector (0.0396, 0.2024, 2.3846)>
After set param 3:  <Vector (0.0396, 0.2024, 2.3846)>
After set param 4:  <Vector (0.0396, 0.2024, 2.3846)>
After set param 5:  <Vector (0.0396, 0.2024, 2.3846)>
After crea1constraint function:  <Vector (0.0396, 0.2024, 2.3846)>
<Vector (0.0396, 0.2024, 2.3846)>
[Lamp, Camera, rFoot, rShin, rThigh, abdomen, lShldr, lForeArm, lHand, rShldr, rForeArm, rHand, head, Behemoth_62096, lThigh, lShin, lFoot, Plane, __default__cam__]
<Vector (-nan, -nan, -nan)>
[Lamp, Camera, rFoot, rShin, rThigh, abdomen, lShldr, lForeArm, lHand, rShldr, rForeArm, rHand, head, Behemoth_62096, lThigh, lShin, lFoot, Plane, __default__cam__]
<Vector (-nan, -nan, -nan)>
[Lamp, Camera, rFoot, rShin, rThigh, abdomen, lShldr, lForeArm, lHand, rShldr, rForeArm, rHand, head, Behemoth_62096, lThigh, lShin, lFoot, Plane, __default__cam__]
<Vector (-nan, -nan, -nan)>

@ both.
It seems to be a bug. But I am not 100% sure.
If you create a constraint and set the pivot angle, setParam will bug. So use a variable (if you need to rotate it) or remove the last three parameters and it should work.
Also please watch about float and int. In that case 0 will work because this methods will convert it to an float. But not every method in blender will do this. So if a parameter a float so don’t write only 0 write 0.0 or .0.

A cone twist constraint has only the parameter 3 to 5. And why you use a cone twist constraint? Wouldn’t a line hinge constraint or a 6DOF motor constraint be fit better?

      axis = 9..11 are rotational motors, with value0=target velocity, value1 = max motor force
         * 9: X axis angle
         * 10: Y axis angle
         * 11: Z axis angle

A line hinge constraint has only a X-Axis limit (parameter 3). Also the joint type for this bone should be a cone twist constraint.

A view days ago (18.7.2014) my patch which is adding the missing documentation and add attribute constraint_type for the ConstraintWrapper was commuted to the master. But You need to wait until the next Blender release before the documentation on the web page will be updated.

This patch?

Or patch for documentation only?

I have long time been waiting that to been include on the master but seems never gonna happen. Then in next version will be included with certain?I need it to continue my final project career of university so I searched a solution for all blender version without I have to applied the previous patch for linux, windows,… thanks

No, only the documentation patch.

I updated and moved T3144 to Differential
But the patch for the physics constraints replication isn’t accepted yet. Moguri want some changes.
Basically for this changes I have to rewrite the whole patch. I think I need one or two days to rewrite and test everything. And Moguri start his new work tomorrow. So I think he want find time to review a new patch next time. So I don’t know if I want to do this because also the future of the BGE is still unclear.

Rumors BGE future:
I think Moguri want still to maintain the BGE.
Ton want to integrate the BGE tighter in Blender, which means that the BGE comes up to an artist presentation engine. But he wants to make some sort of “game” exporter for other engines.
Agoose77 want to integrate Panda3D.

I will wait what comes up at the today’s IRC developer meeting.

Can I help you with the patch? I’m not expert but maybe I can do something. If you want attach code files and tell me about what I will have to do.Thanks


I change this

test_constraints = bge.constraints.createConstraint(physicsid, physicsid2, bge.constraints.LINEHINGE_CONSTRAINT, 0,0,0,0,0,0)

For this

test_constraints = bge.constraints.createConstraint(physicsid, physicsid2, bge.constraints.CONETWIST_CONSTRAINT, 0,0,0)

And now objects not disappear :smiley:

More test, objects not disappear


An with this disappear


If you want you can change the patch regarding Moguri’s requests.

About the conetwist constraint. May be the cone twist constraint is a title bit unstable. I don’t know.
You can try to remove the pivot position to.

test_constraints = bge.constraints.createConstraint(physicsid,  physicsid2, bge.constraints.CONETWIST_CONSTRAINT')

Or use a 6DOF constraint instead.

test_constraints = bge.constraints.createConstraint(physicsid, physicsid2, bge.constraints.GENERIC_6DOF_CONSTRAINT', 0.0, 0.0, 0.0)

I found the fault and have written a bug fix.

i had write this , if can be useful (is only for sixdof)

import bge

def createsixdof(ob1, ob2, pos=[0,0,0], rot=[0,0,0], collision=False):

    class SixDofRefactor:
        def __init__(self, constraint):
            self.constraint = constraint
            self._params =   {
                "limit_position":       {"X": 0, "Y": 1, "Z":2},
                "limit_rotation":       {"X": 3, "Y": 4, "Z":5},
                "motor_linear":         {"X": 6, "Y": 7, "Z":8},
                "motor_angular":        {"X": 9, "Y": 10, "Z":11},
                "spring_linear":        {"X": 12, "Y": 13, "Z":14},
                "spring_angular":       {"X": 15, "Y": 16, "Z":17},

        def set_limit_position_axis(self, axis="X", mn=0.0, mx=0.0):
            self._set_params("limit_position", axis, mn, mx)

        def set_limit_rotation_axis(self, axis="X", mn=0.0, mx=0.0):
            self._set_params("limit_rotation", axis, mn, mx)

        def set_motor_linear_axis(self, axis="X", mn=0.0, mx=0.0):
            self._set_params("motor_linear", axis, mn, mx)

        def set_motor_angular_axis(self, axis="X", mn=0.0, mx=0.0):
            self._set_params("motor_angular", axis, mn, mx)

        def set_spring_linear_axis(self, axis="X", amount=0.0, bounce=True):
            self._set_params("spring_linear", axis, amount, bounce)

        def set_spring_angular_axis(self, axis="X", amount=0.0, bounce=True):
            self._set_params("spring_angular", axis, amount, bounce)

        def remove(self):
            print("not implemented")

        def _set_params(self, kind, axes, v1, v2):
            for letter in axes:
                num_param = self._params[kind][letter.upper()]
                self.constraint.setParam(num_param, v1, v2)

    def check_objects(ob1, ob2):
        if not hasattr(ob1, "meshes") or not hasattr(ob2, "meshes"):
            #should be also checked that the object is not "no collision", not know how
            raise Exception("only mesh object can have physic constraint")

    check_objects(ob1, ob2)

    p1 = ob1.getPhysicsId()
    p2 = ob2.getPhysicsId()
    constraint_numb = 12
    collision_numb = 64 if collision else 128
    constraint = bge.constraints.createConstraint(p1, p2, constraint_numb, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2], collision_numb)

    return SixDofRefactor(constraint)

 example usage

def main():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    if cont.sensors[0].positive: #keyboard
        if not "constraint" in own:
            target = own.scene.objects["Cube"]
            cs = createsixdof(own, target)
            cs.set_limit_position_axis("Z", -10,10)
            # you can set multiple axis writing -> cs.set_limit_position_axis("XYZ", -10,10)
            cs.set_spring_linear_axis("XYZ", 50, 1) # set the limit on all axes
            own["constraint"] = cs