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

move from one random position to another?

Explorer ,
Jun 16, 2017 Jun 16, 2017

Hi,

this is probably simple for someone who knows how to write expressions better then I do. (I hardly do).

I want a Textobject to move from one keyframe to another. Both keyframes should get a random value. (first keyframe-Position somewhere in the upper part of the comp; second key-position somewhere in the lower part of the komp).


Please help. Thanks!

TOPICS
Expressions
5.1K
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

correct answers 1 Correct answer

Advocate , Jun 16, 2017 Jun 16, 2017

Maybe this works for you :

if (numKeys<2){value;}else{

    t1 = key(1).time;

    t2 = key(2).time;

    seedRandom(index*1000+1, true); x1 = random(0, thisComp.width); y1 = random(0, thisComp.height*0.5);

    seedRandom(index*1000+3, true); x2 = random(0, thisComp.width); y2 = random(thisComp.height*0.5, thisComp.height);

    linear(time, t1, t2, [x1, y1], [x2, y2]);

    };

But if you have many layers to animate that way, it's probably easier to use markers (either comp markers or markers on a controller

...
Translate
Advisor ,
Jun 16, 2017 Jun 16, 2017

I'm a little confused as to what you want. If you are keyframing the text object, as you state, you don't need an expression. Just position your object 'randomly' - where you want it ; ) - and set the keyframe to 'hold'. Right click on the keyframe > toggle hold keyframe.

If you want something else, please clarify.

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
Advisor ,
Jun 16, 2017 Jun 16, 2017

Maybe you mean 'frame' not keyframe? If so try this on the position property:

if(timeToFrames()%2 == 0){

random([0,0],[thisComp.width,thisComp.height/2]);

}else{

random([0,thisComp.height/2],[thisComp.width,thisComp.height]);

}

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
Advocate ,
Jun 16, 2017 Jun 16, 2017

Maybe this works for you :

if (numKeys<2){value;}else{

    t1 = key(1).time;

    t2 = key(2).time;

    seedRandom(index*1000+1, true); x1 = random(0, thisComp.width); y1 = random(0, thisComp.height*0.5);

    seedRandom(index*1000+3, true); x2 = random(0, thisComp.width); y2 = random(thisComp.height*0.5, thisComp.height);

    linear(time, t1, t2, [x1, y1], [x2, y2]);

    };

But if you have many layers to animate that way, it's probably easier to use markers (either comp markers or markers on a controller layer) to mark the start and end time of the animation, rather than keyframes.

Xavier

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 ,
Jun 18, 2017 Jun 18, 2017

Hi all,

I will try it out.

Would Marker work on each layer separatly (like keyframes). The layers don't start at the same time and don't have the same duration.

best, rené

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 ,
Jun 20, 2017 Jun 20, 2017

Update: @Xavier

The code is doing what I need! Thank you very much for you help.

best, rené

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
New Here ,
Jul 30, 2021 Jul 30, 2021
LATEST

Hey Xavier, 

 

Where would I enter this expression for it to have an effect on the randomisation of the playback? Can this expression achieve things like this? 

 

https://www.youtube.com/watch?v=0NLLRKGVDl4&ab_channel=MH80

 

Thanks

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