-
Expressions – Changing Position and Storing Previously Calculated Values
I have this simple script :
// Define the duration for the first movement
var duration = 10; // Change position for the first 10 seconds// Get the starting position
var startPosition = position; // The initial position of the layer// Variable to store the specified position
var specifiedPosition;// Check the time to determine the behavior
if (time < duration) {
// Move linearly from the starting position to the new position
var progress = time / duration; // Calculate progress (0 to 1)
var newX = linear(progress, 0, 1, startPosition[0], startPosition[0] + 100); // Example target position
var newY = linear(progress, 0, 1, startPosition[1], startPosition[1] + 100); // Example target position
specifiedPosition = [newX, newY];
} else if (time >= duration && time < 20) {
// Hold the last specified position
specifiedPosition = thisLayer.transform.position.valueAtTime(time – thisComp.frameDuration); // Get the last position
} else {
// After 20 seconds, you can set to hold or do something else
specifiedPosition = thisLayer.transform.position.valueAtTime(time – thisComp.frameDuration); // Continue holding the last position
}// Return the final position
specifiedPosition;At 10 seconds and beyond, I want it to stop calculating a new position and I want it to stay at the last position it had calculated. For some reason though, the position is not sticking and its reverting to its original position that would come from value. It’s a text layer, and I used Source Text to debug and “print” the previous position, and I can see that it is indeed calculating the previous position, but it’s not using that as an actual position! I need help understanding why it’s not holding?? I even tested with another layer and I can referece the previous position of ANOTHER layer but not the current layer? So confused!
Video example:
https://www.youtube.com/watch?v=FbFG0dAuTS8