-
Rotating the Shortest Way Possible
Hi,
How can you ease between 2 values the shortest way possible i.e. ObjA is at 2 degrees and ObjB is at 350degrees, how do you make ObjA rotate 2,10,359,358… etc. rather than 2,3,4,5,6…. The code below weights between 2 values: Value A when Slider is 0, Value B when Slider is 1. Something I can’t figure needs to be added to make it Rotate forwards or backwards depending on which is shortest way:
// On Rotation
var total = 0, totalWeight = 0, remWeight = 0;
var rot = thisComp.layer("Target").transform.rotation);
if (hasParent) rot = parent.rotation;
var fade = effect("Slider Control")("Slider"); // Slider is 0 to 1
total += fade*rot; totalWeight += fade;
remWeight = 1 - totalWeight;
totalWeight==0 ? value : linear(remWeight,total/totalWeight,value);</li-code>