Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Randomizing position when invisible and holding until invisible again

  • Randomizing position when invisible and holding until invisible again

  • Ken Coleman

    May 2, 2021 at 8:43 pm

    Hello everyone! I am pretty much a novice in after effects, so this question may be pretty basic. I’ve tried searching for answers for hours but seem to just be unable to figure this out or even if what I want to do is possible.

    What I’m trying to do is us mask expansion to cause a blot to increase in size, hold there for a bit and then sink back into itself until it isn’t visible. This part I have figured out. Once the expansion is small enough that it is invisible (roughly around -231), I would like to have it randomly generate a new position where it will hold again until it sinks back down and become invisible again. I am trying to refrain from doing anything based on time or just setting up a bunch of keyframes because if I change the length of time the growing and shrinking animation takes then I would need to manually readjust everything. My problem I keep running into is that being unable to store the position value causes it to just reset back to the original position every time the mask makes it visible again.

    I’ve tried various things like randomly generating a position when invisible, but then it just reverts back to the original position once the if-statement isn’t true anymore because it’s no longer being fed a value. I’ve tried to have a timeless randomseed that holds for a very long time and then try setting that time to be very short whenever the if statement is true, but it appears that seeds might not work that way because I seem to be just creating a new one as opposed to overwriting the old one. It still reverts back to the original position once the if-statement is no longer true and then moves permanently only once the original seed’s time has ended.

    So that is a long winded statement leading to: is it possible to use expressions to watch for the mask expansion to reach a specific value, at which point it’s position moves and it holds until the mask expansion reaches that value again which the process starts again? And if so, how might one go about it?

  • Dan Ebberts

    May 3, 2021 at 4:41 pm

    It is possible, but it’s probably the most complicated kind of triggering you can do with expressions. Because expressions have no memory, your expression would need to look at every previous frame up to the current time and calculate how many times the triggering condition (mask expansion going from above -231 to below -231, for example) has occurred. Then use that number (or some multiple of it) as the seed for seedRandom() to generate a new random position.

  • Dan Ebberts

    May 3, 2021 at 4:51 pm

    BTW, the whole thing probably becomes much simpler if you can tap into whatever’s driving the mask expansion to also trigger the random positioning. For example, if the mask expansion is periodic, you could maybe use the same frequency value to trigger each new random position. That would be much more efficient and easier to code.

Viewing 1 - 3 of 3 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy