Copy link to clipboard
Copied
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!
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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]);
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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é
Copy link to clipboard
Copied
Update: @Xavier
The code is doing what I need! Thank you very much for you help.
best, rené
Copy link to clipboard
Copied
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