Skip to main content
Participant
February 22, 2024
Answered

Need an expression that pauses composition playback while there is no position movement

  • February 22, 2024
  • 2 replies
  • 657 views

I've got a looping composition using time remap and LoopOut.

The composition moves randomly from one position to another, then stops (for a random amount of time), then moves to another random point (like a bug crawling around).

 

I'm using this expression for my position:

moveMin = .3; //minimum move time
moveMax = .7; //maximum move time

pauseMin = .1; // minimum pause time
pauseMax = .5; // maximum pause time

minVal = [transform.position[0]-200, transform.position[1]-200];
maxVal = [transform.position[0]+200, transform.position[1]+200];

seedRandom(index,true);  // set pre-run for endT
endT = - random(moveMax);

j = 0;
k = 0;
while ( time >= endT){
  j += 1;
  seedRandom(j,true);
  startT = endT;
  if (j%2){
    endT += random(moveMin,moveMax);
    k++;
  }else{
    endT += random(pauseMin,pauseMax);
  }
}
if (j%2){
  seedRandom(k,true);
  endVal = random(minVal,maxVal);
  seedRandom(k-1,true);
  startVal = random(minVal,maxVal);
  ease(time,startT,endT,startVal,endVal)
}else{
  seedRandom(k,true);
  random(minVal,maxVal)
}

 

I'm trying to have the composition pause/freeze playback while the layer is stopped.

 

Not really sure how to go about it. Any suggestions or help?

Thanks!

This topic has been closed for replies.
Correct answer Dan Ebberts

This might get you close:

f = 0;
accum = 0;
while (f <= timeToFrames(time)){
  if (position.speedAtTime(framesToTime(f)) != 0) accum++;
  f++;
}
framesToTime(accum)

 

 

2 replies

Mylenium
Legend
February 22, 2024

There is no way to "pause" anything. You can't stop the "heartbeat" or else the evaluation would stop entirely. That kind of is the point. You have to manipulate time by directly changing the value as you did, using posterizeTime() or valueAtTime(). Time still keeps ticking away, but the result that is calculated at every frame is the same with the same input and thus appears to be constant/ frozen.

 

Mylenium

Overit-6Author
Participant
February 22, 2024

I thought that might be the case - thanks for the reply!

Overit-6Author
Participant
February 22, 2024

So I found a sort of quick and dirty way to do it, and it works for my needs, but I'm sure there is a better way to actually PAUSE, instead of setting time to zero. But if anyone else comes across this and needs it, I took out my loopOut expression (the comp is now longer and just loops inside of there) and use this on time remap:

velX = Math.round(thisLayer.transform.position.velocity[0]);
velY = Math.round(thisLayer.transform.position.velocity[1]);

if (velX == 0 && velY == 0) {
	0
} else {	
	time
}

 

Not perfect but works for what I need for now.

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
February 22, 2024

This might get you close:

f = 0;
accum = 0;
while (f <= timeToFrames(time)){
  if (position.speedAtTime(framesToTime(f)) != 0) accum++;
  f++;
}
framesToTime(accum)

 

 

Overit-6Author
Participant
February 22, 2024

Ooh perfect, this is exactly what I was looking for. Thank you, Dan!