Skip to main content
Braniac
September 24, 2024
Answered

Expression to pause for commas for Typewriter Text Effect?

  • September 24, 2024
  • 3 replies
  • 989 views

Hi There, very green when it comes to this stuff so sorry if easy.

 

Is there an expression that will add a slight pause to the typewriter write-on text effect whenever there's a comma?

 

Any pointers in the right direction much appreciated. Cheeers, Ben

This topic has been closed for replies.
Correct answer Airweb_AE

Try this:

delay = 0.25
pauseForComma = 0.5
txt = value
characters = txt.length
t = time
displayTime = 0
visibleCharacters = 0
for (i = 0; i < characters; i++) {
  visibleCharacters++

  displayTime += delay

  if (txt.charAt(i) == ",") {
    displayTime += pauseForComma
  }

  if (t < displayTime) {
    break
  }
}
txt.substr(0, visibleCharacters)

3 replies

Airweb_AECorrect answer
Braniac
September 24, 2024

Try this:

delay = 0.25
pauseForComma = 0.5
txt = value
characters = txt.length
t = time
displayTime = 0
visibleCharacters = 0
for (i = 0; i < characters; i++) {
  visibleCharacters++

  displayTime += delay

  if (txt.charAt(i) == ",") {
    displayTime += pauseForComma
  }

  if (t < displayTime) {
    break
  }
}
txt.substr(0, visibleCharacters)

csscmsAuthor
Braniac
September 25, 2024

Thank you! Very much appreciated, marked as correct answer. Cheers

Inspiring
September 24, 2024

From chat gpt (as somebody who doesn't know how to write expressions myself this is always my first stop):

 

Not guarunteed to work but worth a try?

 

Yes, you can add a slight pause in the typewriter effect in After Effects by using an expression that checks for commas and delays the appearance of the next character. Here's a way to achieve this with a simple expression modification.

Steps:

  1. Apply the "Typewriter" preset to your text layer:

    • Select your text layer.
    • Go to the Animation Presets panel, and under Text > Animate In, choose Typewriter.
  2. Open the Range Selector 1:

    • Under the text layer, go to Text > Animator 1 > Range Selector 1 > Advanced.
  3. Add an expression to the Start property:

    • Hold Alt (Windows) or Option (Mac), and click the Stopwatch icon next to the Start property to add an expression.
  4. Use the following expression:

    javascript
    Copy code
    delay = 0.05; // Basic delay between each character pauseForComma = 0.5; // Additional pause for comma (in seconds) txt = value; characters = text.sourceText.length; // Loop through the text and calculate the time based on commas t = time / delay; commas = 0; for (i = 0; i < t; i++) { if (i < characters && text.sourceText[i] == ',') { commas++; } } // Adjust time with comma pauses adjustedTime = time - (commas * pauseForComma); Math.min(adjustedTime / delay, 100);

How It Works:

  • The expression looks at each character in the text and adds a delay whenever it encounters a comma.
  • You can adjust the delay and pauseForComma variables to change the timing between regular characters and how long the pause for a comma lasts.

This will give you a natural typewriter effect with slight pauses after commas, simulating a realistic typing feel.

Inspiring
September 24, 2024

delay = 0.05; // Basic delay between each character
pauseForComma = 0.5; // Additional pause for comma (in seconds)

txt = value;
characters = text.sourceText.length;

// Loop through the text and calculate the time based on commas
t = time / delay;
commas = 0;

for (i = 0; i < t; i++) {
if (i < characters && text.sourceText[i] == ',') {
commas++;
}
}

// Adjust time with comma pauses
adjustedTime = time - (commas * pauseForComma);
Math.min(adjustedTime / delay, 100);

 

here's the code so it's easier to copy/paste

Mylenium
Braniac
September 24, 2024

This doesn't pause on the actual commas, it only lengthens the overall time, so I'm not sure what you are suggesting here.

 

Mylenium

Mylenium
Braniac
September 24, 2024

This is an "all or nothing" scenario. You cannot simply add a line to the preset's expression code and make it magically work. Instead you will have to create a custom expression from scratch using valueAtTime() and string operations. You would check for the commas, count the characters up to that instance of a comma, calculate the effectiver per-character typing duration and then based on that add the delay and remap the timing of the consecutive text. If you have more than one comma, you will have to run it in a loop and then you may need to work around limitations like string and array lengths and everything may be slow due to the constant processing of the retimed typing. point in case: If it's only a few simple lines of text, just animate it by hand with a few extra keyframes.

 

Mylenium