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

Using sourceRectAtTime expression to recreate comments section

New Here ,
Jan 24, 2023 Jan 24, 2023

Copy link to clipboard

Copied

Hello!


I am currently working on a project where I have to recreate the comments section of a youtube live video. I am trying to create a situation where I can type in each comment individually and have the layers adjust to the "posting" of a new comment as though it would on a platform like youtube / tiktok /etc.

I have never used sourceRectAtTime, but it was recommended to me for this. I am also open to any plugins that might solve this conundrum for me as well.

 

I have attached a reference sample of what I'm looking to do (which was created manually).

Any help would be much appreciated!

TOPICS
Expressions , How to

Views

392

Translate

Translate

Report

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

Community Expert , Jan 25, 2023 Jan 25, 2023

You can use sourceRectAtTime() to calculate the height of a text layer. Add inPoint to the end and some padding, and you can easily make a layer jump up when another layer starts. All you need is an expression on the text layer's position property. If you throw in an if statement and interpolate the movement, and put the expression on all but the bottom layer, you can get something like this:

RickGerard_0-1674636491732.gif

 

Here's the expression:

ref = thisComp.layer(index + 1);
refH = ref.sourceRectAtTime().height;
refP = 
...

Votes

Translate

Translate
LEGEND ,
Jan 24, 2023 Jan 24, 2023

Copy link to clipboard

Copied

Completely unnecessary. A simple text layer with a text animator that has its mode set to Line would do everything you need. This isn't anything like those messaging apps with text bubbles.

 

Mylenium 

Votes

Translate

Translate

Report

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 ,
Jan 24, 2023 Jan 24, 2023

Copy link to clipboard

Copied

Ah! after looking into sourceRectAtTime more I was hoping the answer would be a bit simpler. However, I am still relatively new to AE. Would you mind explaining in further detail?

Votes

Translate

Translate

Report

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 ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

You can use sourceRectAtTime() to calculate the height of a text layer. Add inPoint to the end and some padding, and you can easily make a layer jump up when another layer starts. All you need is an expression on the text layer's position property. If you throw in an if statement and interpolate the movement, and put the expression on all but the bottom layer, you can get something like this:

RickGerard_0-1674636491732.gif

 

Here's the expression:

ref = thisComp.layer(index + 1);
refH = ref.sourceRectAtTime().height;
refP = ref.position;
y = refP[1] - refH - 20;// 20 is the padding between layers
x = refP[0];
m = .3; // move time in seconds
t = time - ref.inPoint + m;
if (time <= ref.inPoint - m){
	refP;
}
else{
	y = ease(t, 0, m, refP[1], y);
	[x, y];
}

 

Votes

Translate

Translate

Report

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 ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

This might just be exactly what I need! thank you so much 🙂

 

Votes

Translate

Translate

Report

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 ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

Looks like this is working great so far, but if I add a comment that is a different size than the previous (ie. first comment is 2 lines of text and 2nd comment is 5 lines of text) then the spacing gets messed up. Is there a parameter I need to change to prevent that from happening?

Votes

Translate

Translate

Report

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 ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

LATEST

You must add top and left to the expression to compensate for different layer sizes. I don't have time to rewrite the expression for you, but I do have time to tell you that this expression will return the current position of a text layer no matter what the paragraph justification or the baseline shift is:

ref = thisComp.layer(index - 1);
p = ref.position;
ls = ref.sourceRectAtTime(); // layer size
x = p[0] + ls.width/2 + ls.left;
y = p[1] + ls.height/2 + ls.top;

[x, y]

As long as the Anchor Point of both layers is at the default position, the expression will always position the layer below a text layer exactly at the center of the layer above. 

 

Combine that position plus half the width and the left edge and half the height and the top of a text layer, and you can setup the previous expression to calculate the total move and adjust the spacing based on layer size. Pay attention to how I combined the srAt.left and the srAt.top with the height and width of the layer, and you should be able to fix the problem with multiple lines of text.

Votes

Translate

Translate

Report

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 ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

I mostly was unfamiliar with changing the mode to line, but I have used text animators before. I will do some reading - thank you!

Votes

Translate

Translate

Report

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