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

I want to trigger an animation when two layers overlap using For-Loop

Explorer ,
Nov 04, 2023 Nov 04, 2023

Hi guys, I'm a novice when it comes to expressions. 

So what I want to do is trigger an animation on the Opacity setting going from let's say 25% to 75% taking .5 seconds, when one layer overlaps another. Right now I've got the overlap working but it snaps from 25% to 75%. And I'm guessing I'd have to use a for loop statement for this. I don't think just a linear() statment will work. I tried looking up for loops online but I mostly get the loopOut statments. Any help would be appreciated. Right now my code looks like this and I'm using sliders to adjust the opacity, duration and layer selection of the overlap. 

 

var lyr = effect("Collision Controls")("Select Collision Layer");

var lyrCol = lyr.transform.position;

var nA = effect("Collision Controls")("Collide ON");

var nB = effect("Collision Controls")("Collide OFF");

var dur = effect("Collision Controls")("Duration")

var Alpha = thisLayer.sampleImage(lyrCol, [1,1]) [3];

 

if (Alpha < 1){ nB }else{ nA }

 

Thanks!

 

TOPICS
Expressions , How to , Scripting
431
Translate
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 ,
Nov 05, 2023 Nov 05, 2023

No need to reinvent the wheel:

 

https://www.motionscript.com/design-guide/collision.html

 

Mylenium

Translate
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 ,
Nov 05, 2023 Nov 05, 2023

It's actually kind of tricky. Expressions have no memory, so when your expression wakes up at each frame, it won't know whether or not your opacity ramp has been triggered. If your expression determines that the overlap currently exists, it will need to go back in time, frame-by-frame, to find out when the overlap first occurred (or until it has gone back 5 seconds) to determine where it should be in the opacity ramp. sampleImage() has a built-in time parameter you can use for this. It can get pretty complicated, especially if it's possible for the overlap to end (and what should happen in that case). In any case, there's a bit of code involved and it will include a loop of some kind, but the details will depend on exactly what you want to happen in all situations.

Translate
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
Explorer ,
Nov 05, 2023 Nov 05, 2023
LATEST

Thanks. I think I understand. I did find this  https://www.youtube.com/watch?v=eEEd-YuBHn0

It's not exactly what I was looking for but, you know close enough right now. It uses distance variables between objects to change the values instead of the objectes litterally being on top of each other.

 

 

Translate
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