I am having no luck with the following: I would like to set up a driver that looks at the Z position of an object falling per RB physics (not BGE) and controls some constraint settings based on Z position. To be more specific, I am trying to use a driver to break a constraint or reduce its breakable threshold as the object (constrained with other falling objects) nears the passive ground plane. Any thoughts would be appreciated.
i posted exactly how to do this in your other post almost a month ago.
The following code will work on an object i fractured using Cell fracture, the object named "Cube". then i used the Bullet Constraint tools 'Single constraint' to make the constraints. this code wont work if you have used Empties to constrain the objects together.
and a blend file.
press alt A, you will see the box stays together. run the script (alt P in textblock) and then animate again. you will see the box stays together, until the plane moves above each object.
object_name = "Cube" import bpy for obj in bpy.data.objects: if object_name+"_cell" in obj.name: driver = obj.rigid_body_constraint.driver_add('enabled') driver.driver.expression="this_obj<mask_obj" driver_variable = driver.driver.variables.new() driver_variable.name = "this_obj" driver_variable.type = 'TRANSFORMS' driver_variable.targets.transform_type = 'LOC_Z' driver_variable.targets.id = driver_variable.id_data driver_variable = driver.driver.variables.new() driver_variable.name = "mask_obj" driver_variable.type = 'TRANSFORMS' driver_variable.targets.transform_type = 'LOC_Z' driver_variable.targets.id = bpy.data.objects['mask']