-
Linking the points of a 4-Colour Gradient effect to a Null
Hello.
I have a solid (same size as the comp) with a 4-colour gradient effect applied to it.
I’d like to link each point of the gradient to a null, while keeping their original positions intact.
Basically I’d like the points to follow the transformations of the null (scale, position, rotation).
I tried asking a few AIs, and every expression I was provided with gave me the same error, specifically “Array can’t expand to more than one value”.
I’d kindly ask you to help me achieve what I’m after and to help me understand the whole system better.
I encountered similar issues in the past with other workflows, and I’d generally like to learn how to link the position of a point (Many after effects are controlled by points, like the light sweep for example) to a null, while keeping its original position.
If I pickwhip the point’s position to the position of the null, it shoots out of the composition and I cannot keyframe it.
I attached a screenshot of the error I get.
“Ai_Gradients_Controller” is the Null I mentioned at the begionning, and this is the expression I applied to the 4-color gradient point in question:
// Get the null layer
var nullLayer = thisComp.layer(“AI_Gradients_Controller”);
// Get the initial position of the gradient point
var originalPoint = thisProperty.valueAtTime(0);
// Get the current position of the null layer
var nullLayerPosition = nullLayer.transform.position;
// Calculate the initial offset between the original point and the null layer’s initial position
var offset = [originalPoint – nullLayerPosition, originalPoint – nullLayerPosition];
// Apply the null layer’s rotation to the offset
var rotatedOffset = rotateVec(offset, degreesToRadians(nullLayer.transform.rotation));
// Add the rotated offset to the null layer’s current position
[nullLayerPosition + rotatedOffset, nullLayerPosition + rotatedOffset];
// Function to rotate a vector
function rotateVec(vec, angle) {
var x = vec * Math.cos(angle) – vec * Math.sin(angle);
var y = vec * Math.sin(angle) + vec * Math.cos(angle);
return [x, y];
}Thank you very much for the help.