Drivers: How to have A react to B, like "Set driven key" in Maya?

Hi!

I am looking to do the following (simplified example): Imagine a sphere (character) and a gate. I want the sphere to move on the x axis and when a certain distance from the gate I would like for it to move up and then down once the sphere is trough. Both the sphere and the gate are parented to the same emtpy so the whole assembly can be moved. This means that this should work in local space and not world space so it will work everywhere regardless of where the parent is moved.

In more general terms: I am looking for a way to drive on value with another. I got drivers to work but what I am having problems with is mapping the values. I hope there is a way like Mayaâ€™s set driven key where I can blender: at this sphere position the gate should be here, at this value here and then at this value back to the inital value.

I am sure this is possible, but how?

1 Like

Use a driver of type â€śscripted expressionâ€ť and tinker with the math until the behavior looks like you want it to.

Like this:
Sphere And Gate.blend (530 KB)
The expression for the gateâ€™s local z-axis motion is

max(min(5-abs(var),2),0)

where var is the local y-location of the sphere.

The max(min(â€¦,2),0) restrict the gateâ€™s z-location to between 0 and 2, and the 5-abs(var) means that the gate starts to go up when the sphere is 5 units away on the y-axis, and is fully up when the sphere is 3 units away. The abs() part means that it doesnâ€™t matter from which y-direction the sphere approaches the gate in order for it to go up and down properly.

If this isnâ€™t the behavior you want, you can alter the expression, making the 5 into a 2, for example, or replacing abs(var) with var**2, etc.

Attachments

Sphere And Gate.blend (530 KB)

That was exactly what I needed, thanks!

Well this was my question as well, as it can get more complicated. The reason I was headed ask the question related to set driven key in maya was because Iâ€™m not the best at math. In maya, you just set objectA to key 1. set objectB, key. And you can just keep doing that. And you arenâ€™t limited to two values either.

So No math. If you want to rotate a cylinder around from 249 to 943degrees, and that amount exactly will open the door from 13.45,21.22,43.2 to 14.73,24.76,43.2 then you just set your second key. Now when you rotate your object, maya created the math for you. Sure, you Could script it. But for something that basic, itâ€™s much faster not to have to either tinker, or calculate the math yourself. Notice in my example I had it drive two properties. So Iâ€™d have to do math 8 times to set all the keys. Itâ€™s much faster to just set two keys in that case.

Anyone know of anything like what I described in blender?