Skip to main content
Inspiring
June 13, 2022
Question

Mutually exclusive layers

  • June 13, 2022
  • 3 replies
  • 196 views

Hey guys!

 

I need to do something for a project at work, where layers pop in and out randomly and the user needs to pause the video at the right time to win something.
I'm using this beautiful expression by Dan Ebberts:

fadeTime = framesToTime(4);
curState = wiggle(1,100) < 100;
t = thisComp.frameDuration
while (curState == wiggle(1,100,1,0.5,time-t) < 100){
t += thisComp.frameDuration;
}
tt = time -t;
if (curState){
linear(time,tt,tt+fadeTime,100,0);
}else{
linear(time,tt,tt+fadeTime,0,100);
}

It works, the problem is, I need it on multiple layers and I need control over how many of them are displayed at the same time, because for this to work, they can't overlap.

Is there a good way to do this?

This topic has been closed for replies.

3 replies

Community Expert
June 13, 2022

To be clear, you are trying to create a comp with random layers popping for an AE user to find and modify in some way. 

 

If you are trying to create a video with random popups a viewer can click on, AE is not the right tool. You need an app that controls a media player with multiple time queues or layers. That is out of my expertise.

G5CD7Author
Inspiring
June 15, 2022

Thanks for the replies!
I actually did it expression-less.

I had the artist separate the layers in such a way that it made it a lot easier.

To better explain what it is, it's like this:

 

You have a character that can have multiple skins/colors, and they can equip several different items (helmets, weapons, armor, accessories).

The skin and the items keep randomly rotating around.

Before the video plays, we show you the "target" image with a specific skin and specific items equipped.

Then you watch the video and you try to pause it when you see the character wearing the correct skin and equipment combination, to match the image that you see before the video plays.

So the way I did it was, the main comp has this:

Each layer is one equipment slot comp that keeps changing.

Here's one of those comps:

So there's 4 possible items, and they loop, showing only one item at a time.

In the main comp, there's one "correct" layer which has the desired image show for 10 frames, that's where the user has to pause it.

 

Done 🙂

Thanks for all the help guys, much appreciated!

Dan Ebberts
Community Expert
Community Expert
June 13, 2022

Assuming that all layers in your comp are participating in this random lottery, you could add a new null layer (named "controls") with a slider contol and move it to the bottom of the layer stack. You would then add this exression to the slider:

minDur = .1;
maxDur = .5;
n = index-1;
seedRandom(index,true);
curTime = 0;
curIdx = Math.floor(random(n));
while (curTime <= time){
  curTime += random(minDur,maxDur);
  curIdx = (curIdx + Math.floor(random(1,n)))%n;
}
curIdx + 1 

This expression publishes the layer index of the layer to be visible at any given time. Adjust minDur and maxDur to set the range of times each layer is visible. Then, on all the participating layers, you would add this opacity expression:

s = thisComp.layer("controls").effect("Slider Control")("Slider");
s == index ? 100 : 0

 

Mylenium
Legend
June 13, 2022

Is there a good way? Not really. Is there any way at all? Sure, but it's gonna be a whole lot more complicated than you think and the expression bears no relevance on it, so just copy & pasting it all over the place won't do anything. To figure out which layers are visible you have to store that info soemwhere and that at the very least means having an array e.g. for the layer indices either in the local expression code or globally somewhere so it can be "seen" and accessed by all expressions which could then determine based on the index and/or the order of the array if they need to be visible. How you build the array is entirely up to you and in a simple case could be as trivail as typing in the numbers separated by commas in a text layer and after this do a simple if()else(). For anything more you have to better explain how you envision it to work and how much work we're even talking about. Concocting convoluting expressions makes no sesne for just ten measly layers or something when you could just animate them by hand, you know...

 

Mylenium