Skip to main content
Participant
October 15, 2025
Question

Expression issue: Remapping time to interact with distance between objects.

  • October 15, 2025
  • 0 replies
  • 71 views

Hello!

 

I’m having an issue with an expression.

 

I wanted to create a series of patterns and I thought that I could do this by triggering a pre-comp’s animation with it’s distance from an object. When objA passes over, pre-comp will play 2s - 4s. When objB passes over, play 6s - 8s.

I’ve gotten to a point where the objects interact with the pre-comp’s time, but the output time’s are always off. Instead of 2s - 4s, it will output 2:12 - 4, 6s - 8s will be 6:04 to 8.

 

I assume I’m not understanding linear() or time correctly. Any help would be appreciated!

// Set Pre-comp time

t = thisLayer.time-inPoint;



// Define each object to detect

objB = thisComp.layer("Object B - IN");

objC = thisComp.layer("Object C - OUT");



// Define layer positions

p = thisLayer.position;



xP = transform.position[0];

yP = transform.position[1];



xA = thisComp.layer("Object A - STATIC").transform.position[0];

yA = thisComp.layer("Object A - STATIC").transform.position[1];



xB = thisComp.layer("Object B - IN").transform.position[0];

yB = thisComp.layer("Object B - IN").transform.position[1];



xC = thisComp.layer("Object C - OUT").transform.position[0];

yC = thisComp.layer("Object C - OUT").transform.position[1];



sP = xP + yP;

sA = xA + yA;

sB = xB + yB;

sC = xC + yC;



dP = length(p,objB.position);

dB = length(p, objB.position);

dC = length(p, objC.position);

dBC = length(objB.position,objC.position);



// Define time stamps

// ERROR: time remaping not working. Is linear the wrong function to use?

tStaticOff = 0;

tStaticOn = 6;

tInStart = 2;

tInEnd = 4;

tOutStart = 6;

tOutEnd = 8



// Check distance to each object (in priority order)

if (sP<=sB && sP>=sC && dP <= dBC){

linear(t,0,2, tInStart, tInEnd);

} else if (sP<=sB && dP >= dBC){

linear(t,2,4, tOutStart, tOutEnd);

} else {

  tStaticOff;

}