Creating constraints and collapsing it.

I am wondering if it is possible to constraint an object to another object with rigid body joint in runtime and than unconstraint when needed. How would I do it?:slight_smile:

The bge.constraints API is what you are looking for.

Example creation code:


def joinWheel(wheel):
    obj1 = wheel
    obj2 = obj1.scene.objects[obj1['Connect']]
    
    id1 = obj1.getPhysicsId()
    id2 = obj2.getPhysicsId()
    
    '''bge.constraints.createConstraint(physics_id_1, physics_id_2,
                             constraint_type,
                             edge_position_x, edge_position_y, edge_position_z,
                             edge_angle_x, edge_angle_y, edge_angle_z)'''

    obj1['joint'] = bge.constraints.createConstraint(id1, id2,
                             bge.constraints.GENERIC_6DOF_CONSTRAINT,
                             0,0,0,0,0,0)
                             
    obj1['joint'].setParam(0, 0.0, 0.0) #No X translation
    obj1['joint'].setParam(1, 0.0, 0.0) #No Y translation
    obj1['joint'].setParam(2, 0.0, 0.0) #No Z translation                     
    obj1['joint'].setParam(3, 0.0, 0.0) #No X Rotation
    obj1['joint'].setParam(4, 0.0, 0.0) #No Y Rotation
    #obj1['joint'].setParam(5, 0.0, 0.0)  #But allow to rotate all the way around on Z axis

And to delete:


def deleteWheel(wheel):
    bge.constraints.removeConstraint(wheel['joint'].getConstraintID())

The constraints API is actually quite powerful. You can set joint angles specifically, or set rotation speeds (with torque limits). You can create springs etc.

OK! Does this allow to create multiple constraints for single object? Also, does it work with hinges?

sure, it does. Check the API (yes, I know it is not a well-named or well-documented API).

By the way - what’s the best setup that you can reccomend me for some sort of free hanging cover? Something, that can’t move away, can only rotate at limited range only around 1 axis?

OK! Now my question is more complicated.


In the image above you can see how I’ve set up the 6DOF joint for this. Now I need to know, when to disconnect. I somehow need to know the force exceeded on the object in the direction like shown in image. It must also assume Bullet’s generated forces(e.g. normalforce) with it not just script controlled forces. Is it possible to find out, how strong external force is applied to the object in that exact direction of arrow(relative to the master object)?

Attachments


You can get an approximation to the force on the joint by measuring it’s deflection:
http://www.blenderartists.org/forum/showthread.php?387316-Extracting-force-data-from-rigid-body-joints

OK! Thanks. So when the force on it is gone be large enaugh, it’s gone leave it’s bounds, right?

Well, no matter how small the force you apply to it, it will deflect slightly from it’s position, and that can be measured. Because you can measure it, you can do what you like with that information (ie remove the contraint if it exceeds a value).

OK! So it’s principle is like elastic softbody, suspension, PID controller etc. Try to gain back position IF it is out of it. I am starting to kind of get it:)