Participant
January 19, 2024
Question
Expression not controlling scale properly
- January 19, 2024
- 2 replies
- 179 views
Okay so I'm trying to get a 3d layer to change its scale based on its orbit around a point in 3d space, and the expression isn't working properly. I can add the expression to a text layer and output the values to the source text and see the values changing but sometimes the values never change for the scale.
Here's the expression I'm working with:
// Reference to the null layer's position
var nullLayerPosition = thisComp.layer("Controls for Churchs").transform.position;
var nullPosZ = nullLayerPosition[2];
// Current position of the layer
var currentPosition = transform.position.valueAtTime(time - 0.01);
var currentZ = currentPosition[2];
// Manually calculate scale factor
var maxScale = 100; // Maximum scale when in front
var minScale = 0; // Minimum scale when behind the orbit point
var scaleRange = maxScale - minScale;
var compHalfWidth = thisComp.width / 2;
// Adjust scale based on z position
var scaleFactor;
if (currentZ > nullPosZ) {
// Layer is on the far side of the orbit
scaleFactor = minScale;
} else {
// Calculate scale based on distance to the edge of the orbit in y space
var distanceToEdge = Math.abs(currentZ - nullPosZ);
var scaleProgress = distanceToEdge / compHalfWidth;
scaleFactor = maxScale - scaleProgress * scaleRange;
}
[scaleFactor, scaleFactor, scaleFactor];I've also attached a slimmed down version of the project file as well with the expression(s) that I was using, I also had an expression applied to the position property.
