OK, I would like to use the X location an Empty to control multiple shape keys from another object. Exact values from the X location of the Empty will determine if a shape key is 0% or 100%.
EG,
If Empty Location X = 0.1m then Shape Key 1 = 100% but Shape key 2 = 0%
If Empty Location X = 0.2m then Shape Key 1 = 0% but Shape key 2 = 100%
Etc…
I know that I can use something called an “If/Else” statement to achieve this via drivers per each shape key but I don’t know how.
I tried something similar and it didn’t seem to work. I watched a video where “==” was used to determine an absolute value and tried it out myself and it didn’t work.
This image shows the expression I used and the ‘var’ input. Technically, it looks solid but it’s still not working.
Maybe there is something in the syntax that doesn’t fit?
Because if the location is not exactly 0.01 it will not work. Due to rounding errors the true value might not be the same value that appeatrs in the blender interface.
i think what you’re looking for is an expression that activates a shapekey on a given range of values, ie:
0.0 to 0.1 —> key1
0.1 to 0.2 —> key2
0.1 to 0.3 —> key3
etc.
if so, i mocked it up doing my driver expressions as follows.
for the first shape key:
1 if (var >=0 and var<0.1) else 0
second shape key:
1 if (var >=0.1 and var<0.2) else 0
third:
1 if (var >=0.2 and var<0.3) else 0
etc…
note that you likely want the next shape key to take over at the exact incremental increases of 0.1, 0.2, 0.3, etc, so you make the previous shapes’s driver end just before that value (ie <) and the next shape key include that value (ie >=)
Anyway – never test floating-point numbers for “exact equality.” Even if the value shows up as “0” on the display, it might not be exactly zero. Always use “<” or “<=” operators and such.
@ StrayBillie
Well, in the example video, the guy was using a custom property slider which is why using the “==” was not really a “dangerous” thing.
@ shteeve
Ah, now I know EXACTLY why my version didn’t work for me. You see, I had the following driver expression added to the X location of the empty:
0.01*round(var/0.01)
(‘Use self’ = checked)
So, this way the empty which I would use to control the shape key would snap in increments (without having to actually turn on ‘snapping’ itself). But the ‘background’ values that run even within some sort of constraint to the X location were the numbers used for the actual maths of the expression.
Wow, that was really handy info. Thanks, shteeve!!!
I tried out your expression and it worked like a charm!
To be honest, I wouldn’t have minded to use a slider to use as a controller but I wanted something in the 3d viewport which could be plainly seen and used for the expression to work rather than going through the menus each time.
Lightwave 3d has a function which allows you to create a custom window to use in the viewport that has sliders for you to use for whatever you wanted to. You could even move and shrink the windows to your tastes. Not sure if Blender has anything like that, though.
Thanks again to everyone who helped with this! You guys are awesome!
Alright, so things were working out fine UNTIL one of the shape keys would just not work. I checked the expression with a different control object and it worked. There is nothing wrong with the expression and five of the other expressions for the shape keys work except for this one shape key in the list. I have checked and double-checked that every aspect of the control object, the shape key and the expression and everything is fine except the shape key will not work for this one specific expression (driver). Unfortunately, I cannot provide a copy of the Blend file as it is a private file and I have a total of about 145 shape keys to have working using three control objects (Empties. Oh, and the shape keys and controllers do not conflict in any way with each other, either).
So, ultimately, can drivers just be flaky at times or is there something I need to watch out for?
Even if I delete the driver, copy the previous one and make the appropriate changes, I still have problems with this.
I seriously am appreciative of what you guys have provided but this is one of those funny things that I can’t figure out I’m doing wrong (if it is my work that is the problem, that is.)
To be honest, I don’t see the point in showing the expression since it is exactly the same as for the other shape keys except two of the ‘var’ values. But, since you asked…
1 if (var >=0.04 and var<0.05) else 0
And, as mentioned, I did change the ‘prop’ object from “Morph_Right” to a separate empty which DID work but after switching it back, the shape key did not work.
Also, the former shape keys work using the same expression except for the changed ‘var’ values.
I just think that it is some sort of bug or quirk with drivers but, if it is something else, I’d really like to know.
What that Driver Value is when condition is met? What exactly “shape key would not work” means in this case? Is there difference between empties? Or is it just the fact that you used a different object for that expression when it worked: maybe there’s a conflict in conditions somewhere?
I mean with 145 shapekeys something bound to get mixed up eventually.
There must be something to cause this. I understand if you don’t want to share too much, but don’t dismiss weird behavior as bugs until proven otherwise.
Good luck.
based on your screenshot, it is working correctly: location.x is 0.01, and your driver is set up to only be active between 0.04 and 0.05. are you able to confirm when your Morph_Right’s ‘x’ location is say, 0.045, the expression still fails?
since we don’t have a ton of context to work with for troubleshooting, that would be the first thing i’d confirm.
Wow, shteeve, you are really good!!! I had that driver restricting the X location of the empty to 0.01 increments and as soon as I changed it to 0.001 instead, the shape key worked!
I can’t believe how these simple little things can have such a large impact. It almost seems petty, to be honest, but, hey!, computerz be like dat sumtimez…
The weird thing is that all of the other shape keys (I only did about 6 or 7 of them before stopping and noticing the problem, by the way) worked perfectly fine except that one little shape key!
Thanks again, shteeve! I will definitely be more annoying in the future with more dumb issues like this. I promise