3
$\begingroup$

New to drivers and Python in general, I’ve been playing around with it, but I need to do it without any animations or shape keys, tried a bunch of things with my limited knowledge even combining constraints with drivers, I’ve getting very interesting results but not what I was looking for.

I have two bones: bone1 and bone2. What kind of expression, can I use to affect z location of bone2 to go upwards whenever bone1 moves up, but stop it from moving and keep that position when bone1 moves downward, then as you manually move bone1 up again, bone 2 will start to move up from the position it was left at, and so on.

Someone here said, "a ratchet?"- yes. One example I gave to someone else was those zip ties that only tighten but won't come loose unless you cut them, but that's not quite the use I got for it. There are 2 bones in the scene, bone and bone 1, we need bone 1 to move up by the same amount as bone when bone moves up, regardless of their relative Z locations. But you want bone 1 to stay still when bone moves down, regardless of their relative Z locations. So, bone 1 can only move up and not down, and it always follows bone’s upward movement.

I played around with it a little more, most of the times this would result in a recursive loop when trying to add a third variable representing the difference of these two bones to bone1. Someone suggested I make a custom property to store bone1 last position and have the Python script check it before it performs the action, but I don't know how to go about it.

$\endgroup$
3
  • $\begingroup$ this kind of behaviour makes no sense to me (except you can explain this furthermore...or have another condition) because at a certain time after moving bone1 a lot, bone2 will be lost in space. So i think you need a kind of "reset" of bone2 e.g. at frame 1 for a certain value. $\endgroup$
    – Chris
    Jul 3, 2023 at 5:06
  • $\begingroup$ Do you mean whatever upward motion of bone 1, from whatever start-point -- i.e. a ratchet? $\endgroup$
    – Robin Betts
    Jul 3, 2023 at 8:47
  • $\begingroup$ yes, exactly, a ratchet, one example i gave to someone else was those zip ties that only tighten but wont come lose unless u cut them, but thats not quite the use i got for it. ill try to explain the problem above in better words. yesterday i played around with it a little more, someone suggested i make a custom property to store bone1 last position and have the python script check it before it performs the action, but idk how to go about it. $\endgroup$
    – spatialed
    Jul 3, 2023 at 19:45

2 Answers 2

3
$\begingroup$

You could have an Application Handler:

import bpy

 # Create custom property
bpy.data.objects["Empty"]["prev_Z"] = bpy.data.objects["Empty"].location.z

def ratchet(scene):
    driver_object = bpy.data.objects["Empty"]
    driven_object = bpy.data.objects["Cube"]
    if driver_object.location.z > driver_object["prev_Z"]:
        driven_object.location.z += driver_object.location.z - driver_object["prev_Z"]
    driver_object["prev_Z"] = driver_object.location.z


#bpy.app.handlers.depsgraph_update_pre.clear()
bpy.app.handlers.depsgraph_update_pre.append(ratchet)

enter image description here

$\endgroup$
3
$\begingroup$

First I have to admit I didn't even read the question, since Martynas' answer is accepted and seems to express the problem very clearly, so here's how this can be done with new simulation nodes in Blender 3.6 (yes I've read you ask for a driver specifically, but not sure why, so here's an alternative):

You need to ␣ Spacebar Play the animation in order to make it work (and restarts at frame 0):

$\endgroup$

You must log in to answer this question.

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