3
$\begingroup$
  1. I have two blue bones that move freely along the x axis.
  2. I have mulitple red bones that are ment to only move when they are between the blue bones
  3. the red bones when they are inbetween the blue bones have a location limit of 0 to 0.1 and they have an even distribution value from 0 to 0.1 according to the distance value of the 2 blue bones so there is a nice gradual fall off.
  4. any red bone outside of the left blue bone remains at 0
  5. any red bone outside of the right blue bone remain 0.1
  6. The blue bones can slide past any of these red bones and effect them.

Any ideas on how to achieve this. I have tried a few things.
I have a blend file with thie scene setup. no drivers or constraints yet.[](https://blend-exchange.com/b/6wp4e3BL/)

enter image description here

$\endgroup$
5
  • $\begingroup$ Is this what you mean? It's Spline IK on a 2-point curve, whose ends are hooked. The hooks are parented to your 'blue' bones. (This is not my area, so I'm really waiting for someone who's better at it to answer) $\endgroup$
    – Robin Betts
    Commented Jul 16, 2023 at 9:24
  • 2
    $\begingroup$ I understood it just fine. I will add an answer. $\endgroup$
    – Leander
    Commented Jul 16, 2023 at 9:58
  • $\begingroup$ oh wow really! ty ty $\endgroup$
    – ben
    Commented Jul 16, 2023 at 9:58
  • 1
    $\begingroup$ @RobinBetts thanks for your interest robin, its not what I am after howver its cool to see that IK setup. What I am more after is similar to using a proximity node where object.A passes over Object.B and changes Object.B's location. in this case the two blue bones act as one object in the sense that anything inbetween gets effected. in this case whenthe red bones are inbetween there is a gradual falloff from left to right of each red bones location. hope that can help clarify more $\endgroup$
    – ben
    Commented Jul 16, 2023 at 10:46
  • $\begingroup$ @ben No problem! I hope Leander has got the right end of the stick :) $\endgroup$
    – Robin Betts
    Commented Jul 16, 2023 at 11:44

1 Answer 1

4
$\begingroup$

Add a driver to a red bone and set the world x-positions of the blue bones as two variables in the driver editor.

driver variables

Initially, $L_1 = 0$ and $L_2 = 3$ with your setup.

Then, check Use Self in the driver and enable Auto-Execution for python script in the preferences.

use self

We need the original x-position of the red bone in regards to the space between $L_1$ and $L_2$. But we can't read and write its x-position at the same time. You will either have to use and alternate bone for supplying the initial position (like a parent bone), hard-code the starting value or use the rest position of the armature. I will use the rest position. We shall assume, that the system is not rotated via a parent, and we can rely on only the x-values.

To access the edit bone (which holds the rest position) from the pose bone, use this expression: self.bone.matrix_local.to_4x4().to_translation().x. We need to use the matrix_local in order to get world coordinates.

If the edit bone's global x-position was $1$, the driver would show the following.

edit bone position

Next, normalize the position to the range $(L_1, L_2)$.

(self.bone.matrix_local.to_4x4().to_translation().x - L1) / (L2-L1)

To prevent a division by zero (when L1 and L2 share the same x-position), add a max() expression, to stop L2-l1 from going below 0. Since we have fitted the range of $(0, 1)$ between the blue bones, multiply by your desired range $(0, 0.1)$ at the end.

[...] / max(0.001, L2-L1)) * 0.1

To clamp self.bone.matrix_local.to_4x4().to_translation().x - L1 to the range $(0, 1), use a min(1, [...]) and max(0, [...])` expression.

Python does not have a clamp function.

This is the resulting expression.

min(1, max(0, self.bone.matrix_local.to_4x4().to_translation().x - L1) / max(0.001, L2-L1)) * 0.1

Right click on the driven property and copy-paste it the remaining red bones.

copy driver

We don't need to alter the expression, because it uses self to target its own rest pose location and L1/L2 are shared by all red bones.

$\endgroup$
3
  • 1
    $\begingroup$ I included a lot of explanation. Please let me know if I understood your question correctly. $\endgroup$
    – Leander
    Commented Jul 16, 2023 at 10:40
  • 1
    $\begingroup$ I will definately have a crack at this sir. I will reoprt back when i get it done. thanks so much for taking the time to figure this out. $\endgroup$
    – ben
    Commented Jul 16, 2023 at 10:50
  • $\begingroup$ I am trying the other scenario with being able to rotate the armature. Would I be correct in saying that I would duplicate each redbone so it lies at the original red bones rest position and then use the duplicated bone in the driver panel as a variable so I can reference that bone in the expression instaed of the self.bone. would I unchek the "Use self" button and rewrite the expression to something like min(1, max(0, var - CL) / max(0.001, FL - CL)) * 0.1 $\endgroup$
    – ben
    Commented Aug 7, 2023 at 1:00

You must log in to answer this question.

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