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

How to change the color of the object based on it's side movement.

New Here ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

Imagine this:
A murmuration of Starlings. When a bird moves to the left, it becomes green, and once they start moving to the right, it becomes red. In that way, we'll have green and red birds simultaneously, depending on which side they are moving to.

Does anyone know how to do it in AE, especially the color transition?
The Murmuration, I already found a way.
https://www.creationeffects.com/effects/murmuration-effect

TOPICS
Expressions , How to , Scripting

Views

279

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 ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

I think the simplest approach would be to start with a color expression like this:

v = transform.position.velocity;
v[0] > 0 ? [1,0,0,1] : [0,1,0,1]

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 ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

Thank you Dan.
I tested it with a single element, and it seems to work.
Could you explain the logic of this expression? I'm not very familiar with expression yet.
Would it be possible for me to use orange and purple instead of green and red?

Again, thank you very 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
Community Expert ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

LATEST

The expression just looks at the x component of the layer's velocity (v[0]). If it's positive, the layer is going to the right, otherwise to the left. You could define the colors with variables, like this:

leftColor = [1,.5,0,1]; // orange
rightColor = [.3765,0,1,1]; // purple
v = transform.position.velocity;
v[0] > 0 ? rightColor : leftColor

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