• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

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!

TOPICS
Expressions

Views

342

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 22, 2024 Feb 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)

 

 

Votes

Translate

Translate
Community Beginner ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

This might get you close:

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

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines