0
$\begingroup$

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.

$\endgroup$
1
  • 2
    $\begingroup$ I think it's not ok to post dupes and don't comment on the original answers why they don't work for you. $\endgroup$
    – stacker
    Sep 23, 2014 at 18:51

1 Answer 1

3
$\begingroup$

i posted exactly how to do this in your other post almost a month ago.

Can I use Weight Paint to Control Animation Properties?

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.

https://dl.dropboxusercontent.com/u/14364171/constraint_control.blend

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[0].transform_type = 'LOC_Z'
        driver_variable.targets[0].id = driver_variable.id_data    

        driver_variable = driver.driver.variables.new()
        driver_variable.name = "mask_obj"
        driver_variable.type = 'TRANSFORMS'
        driver_variable.targets[0].transform_type = 'LOC_Z'
        driver_variable.targets[0].id = bpy.data.objects['mask']  

drivers

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .